0

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!
Bista
  • 7,869
  • 3
  • 27
  • 55
Sunny
  • 25
  • 1
  • 5

1 Answers1

0

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.

vadian
  • 274,689
  • 30
  • 353
  • 361