Search code examples
iosiphonecore-datansmanagedobjectnsset

Get NSManagedObject from NSSet


I have NSSet containing NSManagedObjects from NSManagedObjectContextDidSaveNotification notification.
The problem is that: I want to get the type of NSManagedObject in NSSet.
For example, is it Album, User or any other NSManagedObject.


Solution

  • Say you have a managed object called entity, then use the following code to retrieve the name of the managed object:

    NSManagedObjectID *objectID = [entity objectID];
    NSEntityDescription *entityDescription = [objectID entity];
    NSString *name = [entityDescription name];
    

    For clarity I've declared variables on each line, but of course you could also write [[[entity objectID] entity] name]

    I hope this is what you're looking for.