Can I make a property of Realm Object from Enum data type?
所以我有如下自定义数据类型:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
enum WeightUnit : String { case Piece case Gram case Kilogram case Karton case Pouch case Dus case Renteng case Botol init (weightUnitFromServer: String) { } |
并且我希望我的产品(领域对象)具有该
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Product : Object {
@objc dynamic var productID : Int = 0 |
它给出了一个错误:
Property cannot be marked @objc because its type cannot be represented
in Objective-C
那么我可以从枚举中创建领域对象属性吗?如果可能的话怎么做?
我这样做的方法是将对象存储为
1
2 3 4 5 6 7 8 9 |
class Animal: Object {
@objc dynamic var animalClass: String ="" var animalClassType: AnimalClass? { return Class(rawValue: self.animalClass) } enum AnimalClass: String { |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268713.html