Reputation: 29326
When I swipe my UITableViewCell (whose objects are from Core Data) it sets the object for the cell as "read" (in code: isRead
becomes YES
).
This is accomplished as such:
- (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];
}
However, the very next time the app loads the article is back in the unread state (or isRead
is equal to NO
). I made isRead
a transient property in Core Data so whenever it's accessed I can do things to it, and I manipulate it as such:
- (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;
}
Is that somehow confusing it? I don't see what would be causing the change.
Upvotes: 0
Views: 87
Reputation: 17586
Quite simply, transient properties are not stored persistently; they are never written to the database which is why they default back to NO
.
Upvotes: 6