Enqueued from com.apple.main-thread (Thread 1) Crash | iOS | Swift 4.1
Asked Answered
D

1

7

Reference image showing crash

What's happening above:

  1. Initialize realm model from the received array of user data.
  2. Write all the models at once in the realm DB in the background thread.
  3. Realm model is getting updated if they already exist by creating a copy.

Can anyone please guide me here about what I am doing wrong.

Dehypnotize answered 16/4, 2019 at 5:15 Comment(4)
Perform only UI Operation in DispatchQueue.main.async same issue as previous #55646677Ungainly
It's not safe (actually it's an error) to use Realm objects across multiple threads. This may be your problem here. See this advice on how to pass a Realm object to a background thread: realm.io/docs/cookbook/swift/object-to-background You may not be able to use the recipe directly, but it sould give you the idea on what to do...Intemperate
@Peeyush Please updated answer: #55646677Ungainly
@Intemperate Sorry! Thanks and comments deletedUngainly
B
2

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.

Bald answered 18/9, 2020 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.