I'm using realm swift v1.0.0 and I create an object and I want to update its value permanently. Following the official guide and some other answers on stackoverflow I've done:
let myobject = MyObjectClass()
myobject.property1 = "test"
try! myrealm.write {
myrealm.add(myobject)
}
And myrealm is a global variable:
let myrealm = try! Realm()
When I recover all the values of MyObjectClass I get back myobject with some initial values set in the init of the class (so the values that I set as initial values are stored properly), but property1 is (null) (as it is declared as an optional string).
But if I look at myobject in the function where I write the code above, its property1 is set to "test", but it's not saved permanently in the Realm db.
Can anyone help me to find out why it doesn't update the value of property1? I've also tried to do:
try! myrealm.write {
myrealm.add(myobject, update: true)
}
EDIT:
This is my model:
public class MyObjectClass(): Object {
//[...]
public dynamic var property1: String? = nil
public dynamic var property2: MyObjectClass2?
}
Same problem happens with property2 which is another Realm Object.