I hava a core data application. And I want to fetch one kind of object, User. User have the property userId.
I have another array with userIds, [1, 4, 3, 5]. And I would like to create a NSSortDescriptor that sorts my Userobjects based on the order of the userIds in the array.
Is that possible, and how should I do that?
Update
I have now tried the following.
I added a transformable property to my User object, where I store the user ids array.
I have tried the following sort descriptor:
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userId" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) { NSUInteger idx1 = [self.user.followingIds indexOfObject:[obj1 valueForKey:@"userId"]]; NSUInteger idx2 = [self.user.followingIds indexOfObject:[obj2 valueForKey:@"userId"]]; return idx1 - idx2; }];
And I'm getting the following error:
Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. [<__NSCFNumber 0xa337400> valueForUndefinedKey:]: this class is not key value coding-compliant for the key userId. with userInfo {
NSTargetObjectUserInfoKey = 2502;
NSUnknownUserInfoKey = userId;
}
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFNumber 0xa337400> valueForUndefinedKey:]: this class is not key value coding- compliant for the key userId.'
Update 2
Would also like to add a relationship Followers between User objects. Any ideas how that relationship should look? See attached image. Is that correct?
