Inject NSManagedObject into a subclass object

Is there a way to pass an NSManagedObject to a subclassed object?

I have @interface Contact : NSManagedObject , and in the general part of my code I have NSManagedObject , I would like to pass it to Contact so that I can directly access properties using contact.firstName , etc.

I use Contact *contact = myManagedObject; which works at runtime, but I get a compiler warning: incompatible Objective-C types initializing 'struct NSManagedObject *', expected 'struct Contact *' , which I would like to suppress.

+4
source share
1 answer

Use Listing C:

 Contact *contact = (Contact *) myManagedObject; 

Keep in mind that this is pretty little rope. Sometimes you need a rope, of course.

+12
source

All Articles