0
votes

When trying to instantiate my RealmDouble model I get the following error:

*** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value '0' to initialize object of type 'RealmDouble': missing key 'double_value'

class RealmDouble: Object {
    dynamic var double_value: Double = 0.00
}

RealmDouble(value: 0.0)

I have tried deleting the app from the simulator, as well as deleting the Realm file. Does anyone know how to fix this?

2
Can you please share the code you're using to instantiate the RealmDouble instance? - bdash

2 Answers

0
votes

You'd see this exception if you're passing a Double in a place where Realm expects to see either a dictionary from property names to values or an array of values, such as Realm.create(_:value:update). For instance, you'll see an error like this from the following code:

realm.create(RealmDouble.self, value: 0.0)

You should instead do:

realm.create(RealmDouble.self, value: [0.0])
0
votes

From the future if it helps anyone:

Same error was thrown when I accidentally passed the wrong Type on the first parameter of the method realm.create(type: T.Type, value:_, update:_) So make sure type is the correct and set to accept the values you are passing.