该领域已经在写事务中 [英] the realm is already in a write transaction

查看:88
本文介绍了该领域已经在写事务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

领域已经在写事务中.

the realm is already in a write transaction.

如何避免此错误?有没有一种方法可以检查领域是否处于写入牵引状态?如果领域处于写事务中,则先关闭然后执行其他工作.现在,在收到此错误后,该领域已经在写事务中".然后与领域相关的其他任务也无法正常工作.

How can i avoid this error? is there a way to check realm is in write traction? if realm is in write transaction then closed first then do other work. Now after getting this error "the realm is already in a write transaction." then other tasks connected with realm also not working.

推荐答案

Realm的经验法则是在任何给定时间仅在RLMRealm上打开一个写事务.如果遇到此错误,则可能需要重新考虑您的逻辑.您永远不应有意试图在已经在同一线程上打开的RLMRealm上打开第二个写事务.可以在单独的线程上执行该操作,但是第二个写事务所在的线程将被阻塞,直到第一个写操作完成为止.

The rule of thumb for Realm is only one write transaction open on an RLMRealm at any given time. You might need to reconsider your logic if you're hitting this error. You shouldn't ever intentionally be trying to open up a second write transaction on a RLMRealm that's already open on the same thread. Doing it on separate threads is fine, but the thread the second write transaction is on will be blocked until the first one completes.

如果您的实现中有一些设置不正确的内容,则您认为已经完成的事务也可能有错误并处于打开状态.就像塞巴斯蒂安所说的那样,您可以使用-[RLMRealm inWriteTransaction]进行检查,但是在这种情况下,您绝对应该回溯代码以查看发生这种情况的原因.

If there's something in your implementation that isn't set right, it's also possible that a transaction you've assumed had completed might have had an error and was left open. Like Sebastian said, you can check this with -[RLMRealm inWriteTransaction], but in this case, you should definitely backtrack your code to see why that is happening.

这篇关于该领域已经在写事务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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