在Swift中实现核心数据的最佳方式 [英] Best way to implement Enums with Core Data in Swift

查看:178
本文介绍了在Swift中实现核心数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与核心数据实现枚举的最佳方式相似的问题

将Core Data实体绑定到枚举值的最佳方法是什么,以便我可以为实体分配一个type属性?换句话说,我有一个名为Item的实体,一个itemType属性,我想要绑定到一个枚举,在Swift 中执行的最佳方法是什么?

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? 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?

推荐答案

到目前为止,这是我最好的方法。我仍然使用ObjC枚举定义,如Daniel Eggert对同一个ObjC问题的回答中所建议的,因为Swift Enum似乎不能向后兼容ObjC。
因此,我将其添加到我的桥头。

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. Hence, I added it to my bridge header.

这篇关于在Swift中实现核心数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆