Attempting to modify object outside of a write transaction - error in Realm

I also had such a problem, and I decided like this.

let model = RealmModel()
model.realm?.beginWrite()
model.property = someValue
do {
    try model.realm?.commitWrite()
} catch {
    print(error.localizedDescription)
}

self.statistics.summary = 250 needs to be within the write transaction. It should look like this:

if self.statisticsArray.count == 0 {

     try! self.realm.write({
         self.statistics.summary = 250
         self.realm.add(self.statistics)
         self.realm.add(record)
     })
}

Tags:

Ios

Swift

Realm