I have a field that is a Double. I want to change it to a double field. Here's the code I have set up to do that:
schema.get("Item")
.addField("mOriginalWeightUnboxed",double.class)
.transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
Double boxedWeight=obj.get("mOriginalWeight");
if (boxedWeight==null)
boxedWeight=0.0;
obj.setDouble("mOriginalWeightUnboxed",boxedWeight.doubleValue());
}
})
.removeField("mOriginalWeight")
.renameField("mOriginalWeightUnboxed","mOriginalWeight");
Would this be a recommended way of doing that?
Doubleanddoubleare the same for Realm, exceptdoubleis not nullable.So if you want to make a
Doubleinto adouble, then just make the field@Required, and add the annotation for it via migration as well.