kalafun
kalafun

Reputation: 3651

Reusing core data model when updating app - from scratch

My question is fairly simple though I couslnt find anything specifically answering it till yet.

I have an obj-c app that I'm updating fairly often. I would like to create a new swift app with the same bundle id to replace the older one as an update. I have like 8 core data model versions within my old app that I would love to migrate to the new swift-from-scratch-app, so my users wont lose their data. Is it even possible??

Thank u

Upvotes: 1

Views: 266

Answers (1)

bsarrazin
bsarrazin

Reputation: 4040

If you're using the exact same bundle ID (this is key), then from the perspective of iOS, it is considered exactly the same app. Consider your users having version 1.x of your app installed on their devices and you release 2.x using your new Swift project. Your user, nor iOS, will be able to tell this is a brand new app written in Swift.

The gotcha here is that unless you use the exact same model names, CoreData won't be able to be initialized with existing data and you'll be forced to write a custom migration for this.

My suggestion to you is to copy the xcdatamodel file from your old project and change the language of the code it generates once copied into the new project.

enter image description here

Then regenerate your entities in Swift and continue working like nothing ever happened.

Upvotes: 3

Related Questions