单例,类只能通过单例访问,不能自己构造

26. January 2016 Swift 0

import Foundation

class Test {

var s:Int

private static let test = Test(s: 10)

static var shareInstance:Test{

return test

}

private init(s:Int){

self.s = s

}

}

var ss = Test.shareInstance

print(ss.s)

// private 属性作用域是Swift整个文件


Leave a Reply

Your email address will not be published. Required fields are marked *