swift - Realm; making an optional attribute required in future migration -


i have realm model has optional nsdate property expirydate, stores date object no longer usable after.

this property needs changed such expirydate required. because there multiple versions of our app out there, want avoid having function in our data layer checks see if expirydate property on each 1 of objects set, , if not, sets default value.

i plan on updating our schema replace

dynamic var expirydate: nsdate? 

with

dynamic var expirydate: nsdate = nsdate().datebyaddingseconds(somemaxexpirydateinseconds) 

will change mean stored objects expirydate not set, set nsdate().datebyaddingseconds(somemaxexpirydateinseconds) , saved accordingly realm? or property recalculated every time accessed?

it's possible change value types during realm migration, including between making given property optional or non-optional. during migration, have go through , assign value each expirydate object nil.

realm.configuration.defaultconfiguration = realm.configuration(     schemaversion: 1,     migrationblock: { migration, oldschemaversion in         if (oldschemaversion < 1) {             migration.enumerateobjects(oftype: object.classname()) { oldobject, newobject in                 if oldobject["expirydate"] == nil {                     newobject["expirydate"] = date().datebyaddingseconds(somemaxexpirydateinseconds)                 }             }         }     }) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -