LightNight
LightNight

Reputation: 1625

Core Data iPhone

I have method that returned NSManagedObject and I don't know what kind of NSManagedObject it is, because depend of situation this method can return 1 of 3 kind of classes which mark as NSManagedObject. So how can I understand which kind of NSManagedObject it return? For example: firstObj, secondObj, thirdObj.

Upvotes: 0

Views: 75

Answers (2)

Alladinian
Alladinian

Reputation: 35616

To query its entity name you can simply do this:

//Here myObj is your NSManagedObject instance
NSString *entityName  = [[myObj entity] name];

Now if you like further information you could do something like this:

NSEntityDescription *desc = [myObj entity];
NSManagedObjectModel *model = [desc managedObjectModel]; //The managed object model
NSString *className = [desc managedObjectClassName]; //The class name
etc..

For more information see the docs on NSEntityDescription here

Upvotes: 3

Paul de Lange
Paul de Lange

Reputation: 10633

You can use something like:

[obj isKindOfClass: [Subclass class]]

Upvotes: -1

Related Questions