Does Realm support computed property in Swift

大兔子大兔子 提交于 2019-12-11 01:04:01

问题


I'm trying to use a computed property in Realm and use it as primaryKey.

dynamic var eventPrimaryKey: String{
    get{
        return "\(ID)\(eventId)"
    }
}

but I receive this error:

*** Terminating app due to uncaught exception 'RLMException', reason: 'Primary key property 'eventPrimaryKey' does not exist on object

回答1:


You can't use computed property as a primary key, primary key should be stored in database. See more info about primary keys in docs.

Check out Ignored Properties also (note: read-only properties are automatically ignored).



来源:https://stackoverflow.com/questions/37718946/does-realm-support-computed-property-in-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!