Search code examples
swift3realmrealm-mobile-platform

Realm Swift callback function


I use swift3 and Realm 2.3.

And I need callback after transaction is finished.

for example, I have a code as below, how can I get call back after a realm data transaction is finished ?

DispatchQueue.main.async {

     try! self.realm.write {
          self.realm.add(friendInfo, update: true)
     }

}

Solution

  • Transactions are executed synchronously. So you can just perform the code right after you execute the transaction.

    DispatchQueue.main.async {
        try! self.realm.write {
            self.realm.add(friendInfo, update: true)
        }
    
        callbackFunction()
    }