1

In my current app I am currently using MagicalRecord for importing data from a REST API with a UITableView implementing a NSFetchedResultController.

The case where the problem occurs:

  1. I setup a NSFetchedResultController with the predicate as following: [NSPredicate predicateWithFormat:@"friend_type != %i", FacebookFriend];
  2. First I retrieve friends from Facebook which get the friend_type FacebookFriend (from enum).
  3. I will try to resolve their Facebook ID's with a REST API call.
  4. If users were resolved I will change their friend_type to ResolvedFacebookFriend (from enum)
  5. The NSFetchedResultController wont be notified with these changes.

See the following code for initializing my NSFetchedResultController and importing from the data sources.

Creating a NSFetchedResultController via the MagicalRecord library

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"friend_type != %i", FacebookFriend];
self.friendsResultController = [Friend fetchAllGroupedBy:@"friend_type" withPredicate:predicate sortedBy:@"friend_type,user.nickname" ascending:YES delegate:self];

Creating the Friend entity via the MagicalRecord library after the first API call was made to Facebook:

Friend* userFriend = [Friend createEntity];
userFriend.friend_type = [NSNumber numberWithInteger:FacebookFriend];

Updating these FacebookFriends if they were resolved by my local REST API:

Friend* userFriend = [Friend ....] // Correct friend was fetched
userFriend.friend_type = [NSNumber numberWithInteger:ResolvedFacebookFriend];

What could i do to make the NSFetchedResultController be notified by these changes? If not is this a bug of Apple or should I setup my CoreData in a different way?

Edit - 14 November 2013

I found out when the object is saved with the friend_type ResolvedFacebookFriend. And saving it again like this:

userFriend.friend_type = userFriend.friend_type;
// Save the context again

The NSFetchedResultController sees the change all of a sudden and inserts a row into the UITableView.

Wesley
  • 2,190
  • 17
  • 26
  • The FRC has a delegate? – Wain Nov 14 '13 at 11:24
  • Yes with the normal methods implemented like everywhere. controllerWillChangeContent etc – Wesley Nov 14 '13 at 11:28
  • Are the updates from the REST API done in another managed object context? If yes, is that context merged succesfully with the 'main' context? – Leijonien Nov 14 '13 at 12:03
  • Yes and yes they are succesfully merged. i found something out and I will update my post. – Wesley Nov 14 '13 at 12:38
  • What about the FetchedResultController cache? try to reset – Andrea Nov 14 '13 at 12:43
  • [NSFetchedResultsController deleteCacheWithName:nil]; did not work. – Wesley Nov 14 '13 at 12:54
  • http://stackoverflow.com/questions/12370521/changing-a-managedobject-property-doesnt-trigger-nsfetchedresultscontroller-to seems to be sort of the same? – Wesley Nov 14 '13 at 12:58
  • 1
    @Wesso: Did you have a look at the "possible duplicate"? It seems very similar to your problem and provides a workaround to solve it. - The question that you linked to is about changes of an attribute of a *related* entity. That is also a problem with FRC, but seems to be different from your problem. – Martin R Nov 14 '13 at 13:35
  • I checked it out, only using: the willAccessValueForKey:nil seems to work out. Still I would think this is kind of the same as what I do in my edit. There should be a better solution. – Wesley Nov 14 '13 at 13:56

0 Answers0