Swift 单例

class var shareInstance:BaseMainViewController {

struct Static {

static var onceToken : dispatch_once_t = 0

static var instance  : BaseMainViewController? = nil

}

dispatch_once(&Static.onceToken){

Static.instance = BaseMainViewController()

}

return Static.instance!

}


内容转载

swift实现单例的四种方式  http://www.jianshu.com/p/230cc900948c 

Swift中编写单例的正确方式    http://my.oschina.net/jeans/blog/541750                           

你可能感兴趣的:(Swift 单例)