问题
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