How to refresh/update Core Data transient property?

Discussion in 'iPhone/iPad Programming' started by mdhansen5, Aug 4, 2012.

  1. macrumors member

    Joined:
    Nov 22, 2010
    Location:
    Colorado
    #1
    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!
     
  2. macrumors newbie

    SplitIt!

    Joined:
    Jul 10, 2012
    #2
    It sounds like you are not saving your managedObjectContext.

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

    Code:
    NSError * error = nil;
    [your_entity.managedObjectContext save:&error];
    
     
  3. macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #3
    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.
     

Share This Page