我创建了一个这样的单例:
+ (instancetype)sharedDataStore {
static SSDataStore *_sharedDataStore = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedDataStore = [[self alloc] init];
});
return _sharedDataStore;
}
将其保存到document文件夹或从中加载的最佳方法是什么?我尝试使用NSKeyedArchiver保存它,但是之后我不知道如何加载它。我该怎么办而不是
_sharedDataStore = [[self alloc] init];
?
要恢复单身人士的状态,您需要initWithCoder
从NSCoding
协议中实现该方法。就像是:
- (id)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (!self) {
return nil;
}
self.property1 = [decoder decodeObjectForKey:@"property1"];
self.property2 = [decoder decodeObjectForKey:@"property2"];
return self;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句