Cyril Godefroy
Cyril Godefroy

Reputation: 1400

How best to migrate app from sqlite (using fmdb) to CoreData?

I created my App with iOS 2.0, first using the C library directly. Then I moved on to using FMDB (much easier on me). But today, it has become too much of a hassle to manage faulting, caching and prefetching of data. I'm pretty sure that using CoreData would make the app more responsive and lighter (memory-wise).

I'm prepared to go through a long and hard work redoing everything in CD, but I need to migrate existing data. I've considered creating a new model with new objects (CDTrack, CDTrackPoint, CDSegment etc) and then move the existing data that's in objects such as Track, TrackPoint Segment to this new store. But is it really a wise idea? Are there better ways to do it than duplicating the old graph one by one?

Upvotes: 1

Views: 949

Answers (1)

Hunter
Hunter

Reputation: 4371

You're basically on the right track.

What I would probably do is to create an NSOperation for migration that runs when the app starts, if the data needs to be migrated.

Depending on your application, that operation might be able to run in the background (be mindful of Core Data threading rules!), communicating with a main thread NSManagedObjectContext using notifications.

If your app doesn't make any sense without this data migrated, maybe you put up a modal view with a progress indicator while the data is migrating, giving the user a better idea of how long they have left to wait.

Depending on how much data we're talking about, you might be surprised at how quickly Core Data and SQLite can do this sort of thing... The key is to keep the user informed, do it in the minimum amount of time possible and if your application design supports it, do it in the background. Make sure to do the work off the main thread to keep the UI responsive.

Have fun!

Upvotes: 2

Related Questions