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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
didTurnIntoFaultrather thandealloclike you would with a normal object.