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:
- I setup a NSFetchedResultController with the predicate as following: [NSPredicate predicateWithFormat:@"friend_type != %i", FacebookFriend];
- First I retrieve friends from Facebook which get the friend_type FacebookFriend (from enum).
- I will try to resolve their Facebook ID's with a REST API call.
- If users were resolved I will change their friend_type to ResolvedFacebookFriend (from enum)
- 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.