为什么Realm对象中没有我的财产? [英] Why is my property absent from the Realm object?

查看:89
本文介绍了为什么Realm对象中没有我的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Realm进行持久性处理,无法访问标记为只读的属性.

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

更准确地说,我可以使用点符号来打印它们,但是po object仅显示读写属性,并尝试使用objectsWhere崩溃来访问只读属性.

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.

我已经使用标准的NSObject类进行了测试,问题消失了(对于po显然),这让我想知道为什么/如果Realm忽略了只读属性?

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?

推荐答案

那是正确的!如果将属性标记为readonly,则Realm会忽略该属性,并且不会在数据库文件中为其创建备份.这与在RLMObjectignoredProperties方法中放置方法的隐式行为相同.它们保留为传统的Objective-C属性. :)

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. :)

如果需要使该属性在po object命令中可见,则可以覆盖对象的- (NSString *)description方法,并确保您的对象包含在打印的描述字符串中.

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.

由于readonly属性不受Realm支持,因此在使用objectsWhere时,它们将受到很大的限制,因为该属性使用自定义Realm查询引擎.您可能可以检查其他Realm属性是否与该属性匹配,但是无法使用该属性本身作为要搜索的项目来创建查询.

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.

这篇关于为什么Realm对象中没有我的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆