ios - Crashing after lightweight Core Data migration -
i trying master code data migration, going important supporting app. reason need migration preserve data. app used psychological research , collection reaction time data. have game session , every game session has ordered set of moves. every move has properties. 1 of properties interval: date
. in store version 1 named date , in version 2 renamed interval , changed property's model version identifier date.
app not crashing on startup when trying view old logs crashes. have uitextview
, display logs this:
textview.text = "interval = \(move.interval)"
if create new game session , view log - app works.
what best way protect users? should add additional logic inside app this? how can display old data after property renamed?
update:
there's no messages in console, app stops working line of code updating uitextview
, highlighted in green error message:
thread 1: exc_bad_access (code=1, address=0x0)
i tried again scratch , instead of renaming variable, created new one. time app didn't crashed. sorry not real answer helped me move on.
lessons learned:
- do not confuse core data model identifier in xcode inspector , renaming id. there's 1 model identifier (i left empty) , renaming id every property.
- if have core data generated class nsnumber, not try display them in console this:
label.text = "number = \(object.number)"
do this:
label.text = "number = \(object.number.integervalue)"
this 1 gave me same crash message, not problem if you're using nsdate
.
i still have problem when renaming variable. when applied commit again today getting crash right on start can't find model source store
message. app in simulator changed, looks can't reproduce problem more , instead have new one.
update
i had more practice , think able fix crash described above.
i added next data model version - version 3 , introduced new variable. did before, switching current version 2 3. app started crash on launch can't find model source store
. noticed when i'm removing introduced variable app not crashing. figure out core data couldn't migrate version 3 because on version 3:
- i changed version 2 3. didn't change core data model.
- i changed code, fixed bugs unrelated core data.
- built , ran project in simulator. note, app in simulator has data version 3.
- changed core data model, built on simulator. crashed after step.
what did fix this:
- delete introduced variable. can live generated classes is.
- change current version previous. in case, 2 3.
- run app , quit it.
- change core data current version , add new variable.
- run app — works.
update 2
i met problem again , answer didn't helped. still, event after described above.
i found this answer time fixed issue. secret new attributes should not optional , should have default values.
Comments
Post a Comment