Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Chris Holloway
Chris Holloway
2,427 Points

Is it possible to Pre-populate a Core Data model?

I am working on a aviation app. One of the functions requires the device to locate and find the closest airport.

I'd like to preload my airport database into core data, is there a legit way to do this? I've done some looking and what I've found so far appears to be kludgy.

2 Answers

What I have done in the past is essentially bundle a populated sqlite database into the project resources and copy it the the app's document directory on first launch. This tutorial is a little dated but it still works:

http://www.raywenderlich.com/12170/core-data-tutorial-how-to-preloadimport-existing-data-updated

Chris Holloway
Chris Holloway
2,427 Points

Nice! So, this method is feasible for production code as well as development?

I've used it on the app store and the performance impact is almost negligible. It doesn't require any file parsing or database access, just copying data on flash memory.