Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core data managed objects with extra ivars and methods

Is it ok to add ivars and methods to an instance of NSManagedObject?

By "extra", I mean ivars that you don't want serialized.

Do I just add them to my NSManagedObject subclass like any other class or do I have to take any extra precautions?

like image 894
Corey Floyd Avatar asked May 20 '09 00:05

Corey Floyd


People also ask

What is managed object in Core Data?

A managed object context represents a single object space, or scratch pad, in a Core Data application. A managed object context is an instance of NSManagedObjectContext . Its primary responsibility is to manage a collection of managed objects.

What is NS managed object?

In some respects, an NSManagedObject acts like a dictionary—it's a generic container object that provides efficient storage for the properties defined by its associated NSEntityDescription instance.

How do I get NSManagedObject?

Still inside the Core Data editor, go to the Editor menu and choose Create NSManagedObject Subclass. Make sure your data model is selected then click Next. Make sure the Commit entity is checked then click Next again.


1 Answers

You can do exactly what you described. If the ivars aren't in the entity description, they aren't part of the underlying model. Core Data actually has explicit support for NSManagedObject attributes that aren't persisted, though — they're marked "transient". If you do make custom ivars, though, you should remember to let go of the "extra" instance variables in didTurnIntoFault rather than dealloc like you would with a normal object.

like image 172
Chuck Avatar answered Oct 20 '22 01:10

Chuck