我有使用init块的单例
@implementation WSession
static WSession *sharedInstance = nil;
+ (instancetype)sharedInstance {
static dispatch_once_t once;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (id)init {
self = [super init];
return self;
}
它具有CoreData对象的属性
@property (nonatomic) WPlaces *authorizedPlace;
我在屏幕之间使用此属性,并使用MagicalRecord MR_saveToPersistentStoreAndWait保存其他CoreData对象
但是有时候单身人士会失败链接到这个属性并且它变为零。
为什么呢?
xCode调试中的
<WPlaces: 0xa8546e0> (entity: WPlaces; id: 0xa858430 <x-coredata://38FEE7D9-CD17-48B9-891C-D9E0A0142478/WPlaces/p1> ; data: <fault>)
在授权屏幕上
po [WSession sharedInstance].authorizedPlace
<WPlaces: 0xa8546e0> (entity: WPlaces; id: 0xa858430 <x-coredata://38FEE7D9-CD17-48B9-891C-D9E0A0142478/WPlaces/p1> ; data: {
desc = "\U041f\U043e\U0433\U043e\U0440\U0435\U043b\U043e\U0432\U0430 \U0418\U041f";
key = "0dbea37a-4a16-4c30-821c-3819a2741f60";
name = "\U041c\U0430\U0440\U0448\U0430\U043b\U0430 \U0416\U0443\U043a\U043e\U0432\U0430 \U0443\U043b\U0438\U0446\U0430 18";
tag = "\U041c\U043e\U0441\U043a\U0432\U0430";
})
但在下一个屏幕上已经
po [WSession sharedInstance].authorizedPlace
<WPlaces: 0xa8546e0> (entity: WPlaces; id: 0xa858430 <x-coredata://38FEE7D9-CD17-48B9-891C-D9E0A0142478/WPlaces/p1> ; data: <fault>)
(lldb) po [[WSession sharedInstance].authorizedPlace valueForKeyPath:@"key"]
nil
(lldb) po [[WSession sharedInstance].authorizedPlace valueForKeyPath:@"name"]
nil
(lldb)