Why is my property absent from the Realm object?

我与影子孤独终老i 提交于 2020-01-05 04:04:25

问题


I'm using Realm for persistence and I cannot access properties which are marked as readonly.

More accurately, I can print them using dot notation, but po object only shows the readwrite properties, and trying to access readonly properties using objectsWhere crashes.

I've tested using a standard NSObject class and the issue disappears (for po obviously), which makes me wonder why/if Realm ignores readonly properties?


回答1:


That's correct! If a property is marked as readonly, Realm ignores it and doesn't create a backing for it in the database file. This is the same implicit behavior as placing a method in the ignoredProperties method of RLMObject. They are left as traditional Objective-C properties. :)

If you need to make the property visible in the po object command, you can override the - (NSString *)description method of your object and ensure that your object is included in the description string that is printed.

Since readonly properties aren't backed by Realm, they'll be quite limited in what you can do with objectsWhere, as that uses a custom Realm query engine. You can probably check if other Realm properties match that property, but you couldn't create a query using the property itself as the item being searched for.



来源:https://stackoverflow.com/questions/41018843/why-is-my-property-absent-from-the-realm-object

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