简体   繁体   English

在Swift中用核心数据实现枚举的最佳方法

[英]Best way to implement Enums with Core Data in Swift

Very similar question to Best way to implement Enums with Core Data 使用核心数据实现枚举的最佳方法非常相似的问题

What is the best way to bind Core Data entities to enum values so that I am able to assign a type property to the entity? 将Core Data实体绑定到枚举值以使我能够为该实体分配类型属性的最佳方法是什么? In other words, I have an entity called Item with an itemType property that I want to be bound to an enum, what is the best way of going about this in Swift ? 换句话说,我有一个名为Item的实体,该实体具有itemType属性,我想将其绑定到枚举, 在Swift中解决此问题的最佳方法是什么?

So far, this is my best approach. 到目前为止,这是我最好的方法。 I still use the ObjC enum definition, as suggested in Daniel Eggert's answer to the same ObjC question as the Swift Enum doesn't seem to be backward compatible to ObjC. 我仍然使用ObjC枚举定义,正如丹尼尔·埃格特(Daniel Eggert)对相同的ObjC问题的回答所建议的那样,因为Swift Enum似乎并不向后兼容ObjC。 Hence, I added it to my bridge header. 因此,我将其添加到了桥头中。

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

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