OGeek|极客世界-中国程序员成长平台

标题: ios - 我可以在 Realm 的线程中使用被忽略的属性吗? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:55
标题: ios - 我可以在 Realm 的线程中使用被忽略的属性吗?

对于在线程之间共享的对象(通过持久化和查询),在一个线程中对被忽略的属性所做的更改是否会在另一个线程中可见?

To share objects between threads or re-use them between app launches you must persist them to a Realm ... all changes you make to it will be persisted (and must be made within a write transaction). Any changes are made available to other threads that use the same Realm when the write transaction is committed.

http://realm.io/docs/cocoa/0.91.1/#writes

看起来这适用于被忽略的属性。每个线程的对象实例都有自己的被忽略属性的副本,并且一个线程中的更改不会影响任何其他线程。对吗?



Best Answer-推荐答案


正确。当您通过重新查询从另一个线程访问 RLMObject 时,它将是该对象的一个​​新实例,因此被忽略的属性不会与该对象一起携带。

话虽如此,只要您不尝试访问任何 Realm 支持的属性(否则将触发 RLMException),您可以传递 RLMObject 实例从一个线程到另一个线程,并且仍然继续在新线程上访问其被忽略的属性。

关于ios - 我可以在 Realm 的线程中使用被忽略的属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29358849/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4