- (NSMutableArray *)orderArray {
if (!_orderArray) {
_orderArray = [NSMutableArray array];
}
return _orderArray;
}
过去多啦不再A梦2017-05-02 09:22:56
If you are correct, it should be the attribute get method in Objective-C.
Actually, @Tr2e was almost completely correct. His answer could have been improved with a slight modification:
lazy var orders: [AnyObject] = []
NO:
// 如果省略 `:` 后面的类型的话,orders 的类型会变为 NSArray,
// 而不是 Swift 的类型,也不是 NSMutableArray
lazy var orders = []
(PS: orders is a better name)
大家讲道理2017-05-02 09:22:56
Single case?
If hard translation
func orderArray()->NSMutableArray{
if _orderArray != nil {
_orderArray = NSMutableArray.array()
}
return _orderArray
}
Swift point
// 单例类
class SharedObject {
static let sharedInstance = SharedObject()
}
// 使用
SharedObject.sharedInstance.doSomething()
PHP中文网2017-05-02 09:22:56
There is a keyword called lazy, which is roughly like this:
lazy var array = { let a = NSArray.init(); return a }()