enum LazyValue{ case NotComputed(()->T) case Computed(T)}class LazyClass{ private var _value : LazyValueinit(computation:()->T){
self._value = .NotComputed(computation)
}
//get Method
var value : T {
switch self._value {
case .NotComputed(let temp):
let result = temp();
self._value = .Computed(result)
return result
case .Computed(let temp):
return temp;
}
}
}
网友评论