Search code examples
iosobjective-ccore-datansset

core data - check if in a NSSet exists a nsmanagedobjectID


I saw this answer and this is really what I need (Does a Core Data NSSet contain an object with a certain ID?), but the used ID in there is a user customized ID. Is it possible to check if a object with a specific NSManagedObjectID exists in a NSSet? How can I do that with KVC?


Solution

  • Given that

    NSSet* mySetOfObjects;
    

    contains your NSManagedObjects and you are looking for

    NSManagedObjectID* specificObjectId;
    

    the following should work:

    [[mySetOfObjects valueForKeyPath:@"objectID"] containsObject:specificObjectId];