0
當我滑動我的UITableViewCell(其對象來自核心數據)時,它將單元格的對象設置爲「讀取」(代碼:isRead
變爲YES
)。爲什麼我重新加載應用程序時,Core Data中的布爾值發生了變化?
這是通過這樣:
- (void)swipedToMarkCellRead:(Article *)article {
if ([article.isRead isEqualToNumber:@YES]) {
article.isRead = @NO;
}
else {
article.isRead = @YES;
}
NSManagedObjectContext *context = self.managedObjectContext;
NSError *error;
[context save:&error];
}
然而,非常下該應用加載文章時間是早在未讀狀態(或isRead
等於NO
)。我做了isRead
瞬態特性在覈心數據所以每當它進入我可以做的事情吧,我操縱它是這樣:
- (NSNumber *)isRead {
[self willAccessValueForKey:@"isRead"];
NSNumber *isRead = [self primitiveValueForKey:@"isRead"];
[self didAccessValueForKey:@"isRead"];
// If at 100% progress (finished) or it's already marked as read
if ([self.progress intValue] >= 1 || [isRead boolValue]) {
isRead = @YES;
}
else {
isRead = @NO;
}
return isRead;
}
是不是有點難以理解呢?我不明白會導致這種變化。
如果你想存儲的價值不應該是一個短暫的屬性應該呢? –