Mustafa ALMulla
Mustafa ALMulla

Reputation: 900

Updating Realm Object in Swift from in Different thread/session

After saving the realm objects i doing the following

 try! self.realm.write{
       article.imageUri = path
       try! self.realm.commitWrite()
 }

although I can see the value while i am still in the same session of the simulator, after restarting or rerunning the app the update value in the snippet above doesn't show, but the rest of the data is there

this update is done after fetching data using Alamofire result

Upvotes: 0

Views: 877

Answers (1)

tbondwilkinson
tbondwilkinson

Reputation: 1087

First thing, when you call write with a block, you don't need to specify try! self.realm.commitWrite() inside the block. That's automatically called for you as per Realm's example:

try! realm.write {
  realm.add(myDog)
}

You only need to call self.realm.commitWrite() when you have previously called self.realm.beginWrite()

Secondly, It's hard to say exactly why you might not be seeing the data update with more context. What's article? Where's that being set? How is the Realm being loaded/stored? Are you deleting the Simulator app in between runs? There's a lot of variables here.

Upvotes: 3

Related Questions