Welcome to the iMore Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 2 of 2
  1. Thread AuthorThread Author   #1  
    danbretl's Avatar
    iPhone Nanite

    1 Posts

    Default NSFetchedResultsController not responding to data updates properly

    I have a data model for a basic photo sharing app where every Photo is associated with a single Feeling and User. The main Gallery VC has a table view of Feelings. You can sort those Feelings either alphabetically or chronologically (with the Feeling that has a Photo added to it most recently at the top). When in "Recent" mode (and possibly in "Alphabetical as well, though I have not confirmed this), the table view is not updating properly. The data is being updated correctly in the MOC, and the NSFetchedResultsController is tracking those changes and sending delegate callbacks to my Gallery VC, but it is not really doing it successfully... The data it reports is correct, but "Move" changes are often reported merely as "Update", so that a row for a recently updated Feeling is not moving to index 0. (If you force a re-fetch though, the display corrects itself.) When a Feeling row does move to the top successfully, often the second row also shows as that Feeling. (If you scroll those rows off screen and back on though, the display corrects itself.)

    You can download a super-stripped-down version of the project at GitHub. Any help would be greatly appreciated. https://github.com/danbretl/NSFetche...trollerTrouble
  2. #2  
    ballsy's Avatar
    iPhone Nanite

    1 Posts

    Default Solution Found


    I had been battling with this same problem for a week and I finally worked out the solution. I had a background thread updating the same MOC that my FRC was using in the main thread. From what I can gather, the MOC is not thread-safe so you need to create a new MOC for each thread, although it can use the same PSC. To confirm if this works for you, temporarily run your updates to the MOC in the main thread by wrapping them (including the save) in

    dispatch_sync(dispatch_get_main_queue(), ^{ *changes in here* });

    I hope this helps.