ios - 我可以在 Realm 的线程中使用被忽略的属性吗?

标签 ios objective-c multithreading 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

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

最佳答案

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

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

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

相关文章:

ios - didEnterRegion 永远不会在 ios 中被调用

iphone - 如何设置受密码保护的网站来测试 HTTP 身份验证质询?

ios - 以编程方式返回到不同 Storyboard 中的先前 ViewController

c# - 该进程无法访问该文件,因为该文件正在被另一个进程使用

c# - Parallel.ForEach() 与 foreach(IEnumerable<T>.AsParallel())

ios - 如何使 UINavigationBar 完全透明或像这样消失只能看到标题和 UIBarButtonItem

ios - 如何根据 HTML 内容动态更改 UIWebView 的高度?

iOS - 陀螺仪示例

iphone - 在启动时自动实例化单例

java.exe 没有结束 - 只剩下一个操作系统线程