从com.apple.main-thread(线程1)入队iOS |斯威夫特4.1 [英] Enqueued from com.apple.main-thread (Thread 1) Crash | iOS | Swift 4.1
问题描述
上面发生了什么:
- 从接收到的用户数据数组初始化领域模型.
- 在后台线程中的领域数据库中一次编写所有模型.
- 如果通过创建副本,Realm模型已经存在,则会对其进行更新.
任何人都可以在这里指导我有关我做错了什么.
Can anyone please guide me here about what I am doing wrong.
推荐答案
我遇到了类似的问题.在这里,您可能正在从其他线程访问领域对象.例如:您可以使用调度队列,但是更有可能在另一个线程中声明您要访问的对象.您可以在任何线程中都有一个领域对象,但是访问该领域对象的属性将导致崩溃.就我而言,我是从一个单例访问一个领域对象数组,该单例在另一个线程中初始化.即使我添加了DispatchQueue关闭,它也会导致错误,因为我尝试访问的对象在另一个线程中.
I faced a similar problem. Here you might be accessing realm object from different thread. For eg: You can use the dispatch queue, but there is a higher chance that the object you are trying to access is declared in another thread. You can have a realm object in any thread, but accessing a property of this realm object will lead to a crash. In my case, I was accessing an array of realm objects from a singleton which is initialized inside a different thread. Even if I added DispatchQueue closure it caused an error because the objects which I tried to access were in another thread.
这篇关于从com.apple.main-thread(线程1)入队iOS |斯威夫特4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!