OH: "How do you make a singleton in Swift?"—
Conversation
class Test {
class let sharedInstance = Test()
}
Type properties are computed lazily.
3
8
30
Replying to
Replying to
Use a nested struct within a class, create a struct level instance, and make a readonly class var returning the instance.
2
@unicodescalar like this? is there a better way to name? Foo.Shared.Instance ? gist.github.com/pj4533/6714ba3
1
Show replies



