0

For example, consider this class:

class Foo {

    private init() {

        // Private init, so no instances can be created.
        // All methods and properties will by owned by the type.
        // So no instances will need to be created,
        // as there is no instance functionality.

    }

    static var count = 0
    static func increment() {
        Foo.count += 1
    }

}

Perhaps it makes no difference whether it's a class or a struct? (assuming inheritance isn't needed).

Peter Parker
  • 2,121
  • 1
  • 17
  • 23
  • So... why aren't you using a static class? You can't make an instance of a static class, so it seems like that'd match your use case. – cwharris Aug 27 '18 at 19:32
  • @cwharris I haven't heard of a static class before (I first thought you meant a class with all static members), but according to this post https://stackoverflow.com/questions/42935707/are-static-classes-supported-by-swift/42935763, Swift doesn't have them. – Peter Parker Aug 27 '18 at 19:42
  • excuse me. I was filtering questions incorrectly. ignore my comment entirely. – cwharris Aug 27 '18 at 19:43
  • 1
    This is an uncommon pattern, enums with no cases are better candidates for namespacing. – Cristik Aug 27 '18 at 19:58
  • 1
    Related: https://stackoverflow.com/questions/38585344/swift-constants-struct-or-enum – Martin R Aug 27 '18 at 20:05

0 Answers0