简体   繁体   中英

Copy core data file model from Objective-C app to brand new Swift 3 project

I have a first version of an iOS app written in Objective-C using core data.

I am now in the process of totally re-writing the app from scratch in Swift because the Objective-C version is very buggy.

The goal is to keep the database content in the app, after updating from Objective-C to Swift version. Users should not lose data.

In the Swift project, I used the .xcdatamodel that was automatically generated and I recreated all Entities and Relationships exactly based on the Obj-c .xcdatamodel file. Bunddle identifier is the same for both version. In the simulator, one is replacing the other when I run projects. But the database is erased each time.

I found several topics explaining lightweight or heavy migration, but always related to a data model change inside the same project.

Is it possible to copy the old .xcdatamodel file into the new project? I tried but without any success. Maybe problems are that files are named differently and that projects are written in different languages.

Copying a model file to a new project is literally as simple as copying the file.

If you have both Xcode projects open, you can drag the file from one project into the other. Xcode will ask what you want to do-- make sure that "Copy items if needed" is checked. Click "Finish" and you're done.

Or do it in Finder. Duplicate the old file, move the duplicate into the new project's folder, and rename it if necessary. Then switch to Xcode and tell it to add the new model file ("File" menu --> "Add files...").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM