简体   繁体   中英

Can I add standard ivars and properties to an NSManagedObject?

Can I add standard properties to an NSManagedObject. I don't expect these objects to be saved, but I would like them to persist for the lifetime that the application is running.

Can I add a getter and setter backed with an ivar?

Yes, you can add your own properties and methods to a class derived from NSManagedObject. I do this all the time. You can declare the properties @dynamic (if using Core Data), or simply @synthesize them.

In this case "transient properties" are commonly used. You declare them in your Core Data Model like your other Entity properties but flag them as "transient" in the data model inspector. They are part of your Core Data model, but not persisted! 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM