I have defined a Core Data for my project and implemented an ENtity:attribute called isRealEntry
.
@interface FTRecord : NSManagedObject
@property (nonatomic) NSTimeInterval lastUpdated;
@property (nonatomic) BOOL isRealEntry;
@end
Now when I save the context (NSManagedObjectContext *context;
)
NSError *error = nil;
BOOL successful = [context save:&error];
I would like to save only those entities that have a true isRealEntry
, otherwise the entry shall be ignored or undone.
How can I achieve this?
Update:
At first I found Martin's solution very promising. However I get a very nasty side effect when I save my data upon entering background:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[FTRecordStore sharedStore] saveChanges];
}
When I resume the app, all the previous deleted records aren't gone for real but flagged to be deleted. The array still seems to have all of them (real or unreal in my case). The cells go completely nuts and show empty for all records.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FTRecord *record = [[[FTRecordStore sharedStore] getAllRecords] objectAtIndex:[indexPath row]];
FTRecordCellView *cell = [tableView dequeueReusableCellWithIdentifier:@"FTRecordCellView"];
[[cell notesLabel] setText:[record notes]];
return cell;
}
I am not sure how to solve this. My Store is a singleton. getAllRecords determines above the content for each cell. Hence I need to have the same value for getAllRecords as also in the tableView, or it would crash.
The other suggested solution with two sources one in memory and in db seems also not to be possible, how do I feed one TableView with two sources?
Update 2:
I had an embarassing oversight. Deleting the record from context is not enough. I also had to delete it from the array.
[allRecords removeObjectIdenticalTo:record];
Therefore I take it back. Martin's solution works perfect. However I am still curious to know if a UITableView can indeed be driven from two sources (db/memory) as suggested in teh other solution. Thanks