何为对象初始化,懒加载不是在首次调用的时候才初始化的么?这个不同样是RAII么?
class MyClass {
int value;
MyClass() {
value = 10;
}
}@implementation MyLazyObject
- (id)init {
self = [super init];
if (self) {
_lazyProperty = nil;
}
return self;
}
- (NSObject *)lazyProperty {
if (_lazyProperty == nil) {
_lazyProperty = [[NSObject alloc] init];
}
return _lazyProperty;
}
@endLast updated