PDA

View Full Version : How to refresh/update Core Data transient property?




mdhansen5
Aug 4, 2012, 10:07 PM
I'm using a core data, NSFetchedResultsController UITableView, with a transient NSDate attribute. The main reason I have this as a transient property is so my UITableView entries get put into sections based on NSDate, but can move between the sections when the date changes.

So far it seems to work great, but it only updates/refreshes (I'm really new to this, so I don't know if I'm using the correct terminology, sorry!) when I either close the app and kill it from multitasking, or re-run it through Xcode. If I don't do that, the items don't change and aren't put into their correct sections. Is there a way to manually get it to refresh so the user doesn't need to do that to get it to run right?

Thank you!



SplitIt!
Aug 4, 2012, 10:28 PM
I'm using a core data, NSFetchedResultsController UITableView, with a transient NSDate attribute. The main reason I have this as a transient property is so my UITableView entries get put into sections based on NSDate, but can move between the sections when the date changes.

So far it seems to work great, but it only updates/refreshes (I'm really new to this, so I don't know if I'm using the correct terminology, sorry!) when I either close the app and kill it from multitasking, or re-run it through Xcode. If I don't do that, the items don't change and aren't put into their correct sections. Is there a way to manually get it to refresh so the user doesn't need to do that to get it to run right?

Thank you!

It sounds like you are not saving your managedObjectContext.

After you update one of your entity's date attribute, save the managed object context.


NSError * error = nil;
[your_entity.managedObjectContext save:&error];

MattInOz
Aug 5, 2012, 12:46 AM
Transient properties don't save to the persistent store. That is the point of them being transient, your saying to the store don't bother saving this data i can recreate it as needed.

There are a couple of ways to recreate them. One which might be simplish is to create a sub-class for your Entity. Then you can overwrite the
-awakeFromFetch
method to repopulate the transient fields as the entity gets pulled from the store.

Trying to hunt round for a good tutorial. Will post later if i find.
The other useful method that could be of interest is
-awakeFromInsert
which you could use to set the value went you create the object.