标签:
在 iOS 开发中,懒加载是无处不在的
lazy var person: Person = {
print("懒加载")
return Person()
}()
let personFunc = { () -> Person in
print("懒加载")
return Person()
}
lazy var demoPerson: Person = self.personFunc()
lazy var demoPerson: Person = Person()
getter & setter
很少用,以下代码仅供了解private var _name: String?
var name: String? {
get {
return _name
}
set {
_name = newValue
}
}
var title: String {
get {
return "Mr " + (name ?? "")
}
}
var title: String {
return "Mr " + (name ?? "")
}
var title2: String {
return "Mr" + (name ?? "")
}
lazy var title: String = {
return "Mr " + (self.name ?? "")
}()
标签:
原文地址:http://www.cnblogs.com/evening015/p/5365028.html