2013-11-04 36 views
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; 
} 

是不是有點難以理解呢?我不明白會導致這種變化。

+0

如果你想存儲的價值不應該是一個短暫的屬性應該呢? –

回答

相關問題