In a class I would previously create a shared instance like so:
class MenuConfigurator
{
// MARK: Object lifecycle
class var sharedInstance: MenuConfigurator
{
struct Static {
static var instance: MenuConfigurator?
static var token: dispatch_once_t = 0
}
dispatch_once(&Static.token) {
Static.instance = MenuConfigurator()
}
return Static.instance!
}
}
It seems the Swift 3.0 migration tool has changed the block of code to:
class MenuConfigurator
{
private static var __once: () = {
Static.instance = MenuConfigurator()
}()
// MARK: Object lifecycle
class var sharedInstance: MenuConfigurator
{
struct Static {
static var instance: MenuConfigurator?
static var token: Int = 0
}
_ = MenuConfigurator.__once
return Static.instance!
}
}
I am getting the error Use of unresolved identifier Static
. What is happening here? Why has the new var private static var __once
been created?