import UIKit
class SharedInfo: NSObject {
var nameStr:String? = "123" //设置初始值
struct ToolP {
static var myTool:SharedInfo?=nil
}
class func shareMyTool()->SharedInfo {
if(ToolP.myTool == nil){
ToolP.myTool=SharedInfo()
}
return ToolP.myTool!
}
}
调用方法
var myTool = SharedInfo.shareMyTool()
myTool.nameStr = "12312342423" // 此时nameStr的值是 :12312342423
var myTool2 = SharedInfo.shareMyTool()
String name = myTool2.nameStr
print(name!)