How can I convert this to Swift 3:
struct Static {
static var instance : myForm?
static var token : dispatch_once_t = 0
}
dispatch_once(&Static.token) {
Static.instance = myForm()
}
return Static.instance!
Just this:
static let instance = MyForm()
and call it
let form = MyForm.instance
A note from the documentation:
Stored type properties are lazily initialized on their first access. They are guaranteed to be initialized only once, even when accessed by multiple threads simultaneously, and they do not need to be marked with the
lazy
modifier.
PS: Consider that struct
and class
names are supposed to start with a capital letter.