Realm是否在Swift中支持计算属性 [英] Does Realm support computed property in Swift
本文介绍了Realm是否在Swift中支持计算属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Realm中使用计算属性并将其用作primaryKey.
I'm trying to use a computed property in Realm and use it as primaryKey.
dynamic var eventPrimaryKey: String{
get{
return "\(ID)\(eventId)"
}
}
但我收到此错误:
*** Terminating app due to uncaught exception 'RLMException', reason: 'Primary key property 'eventPrimaryKey' does not exist on object
推荐答案
您不能将计算属性用作主键,主键应存储在数据库中.在文档中查看有关主键的更多信息.
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).
这篇关于Realm是否在Swift中支持计算属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文