简体   繁体   English

我可以将标准的ivars和属性添加到NSManagedObject吗?

[英]Can I add standard ivars and properties to an NSManagedObject?

Can I add standard properties to an NSManagedObject. 我可以将标准属性添加到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? 我可以添加一个用ivar支持的getter和setter吗?

Yes, you can add your own properties and methods to a class derived from NSManagedObject. 是的,您可以将自己的属性和方法添加到从NSManagedObject派生的类中。 I do this all the time. 我一直这样做。 You can declare the properties @dynamic (if using Core Data), or simply @synthesize them. 您可以声明@dynamic属性(如果使用Core Data),或者只是@synthesize它们。

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! 它们是您的Core Data模型的一部分,但不会保留! 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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