Search code examples
iphoneiosxcodecocoa-touchnsmanagedobjectcontext

fetchObjectsForEntityName: not recognised as valid method


This code is really confusing me. When I type in fetchObjectsForEntityName, it doesn't offer suggestions, and then afterwards gives me a warning of No visible @interface for 'NSManagedObjectContext' declares the selector 'fetchObjectsForEntityName:withPredicate:'.

Here's the code:

-(SyncObject *)objectWithSyncID:(NSString *)syncID inContext:(NSManagedObjectContext *)context {

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"syncID == %@", syncID];

    NSSet *set = [context fetchObjectsForEntityName:@"SyncObject" withPredicate:predicate];

Solution

  • Because the method doesn't exist. I guess you copied some code from a tutorial but you didn't copy all of it. There should be a category on NSManagedObjectContext which defines and implements the method.