Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading a Core Data / SQLite Database into an app ?

Would it theoretically be possible to download a Core Data database straight into an app and then access this database ?

If so what formatting considerations would there be - would any SQLite database work or would a specific structure be required ?

like image 520
GuybrushThreepwood Avatar asked Aug 08 '26 02:08

GuybrushThreepwood


2 Answers

Core Data's database structure is closed meaning that you cannot and should not attempt to replicate it. The only recommended way to download a pre-populated database is to use Core Data. Fortunately OS X and iOS share the exact same structure (and will do so going forward).

The recommended way to handle this is to write a CLI for OS X that generates the SQLite file for you. Then you can download that file into your application as needed. This is also recommended for shipping a pre-populated database with your application (which is usually a better option than downloading an entire file).

like image 151
Marcus S. Zarra Avatar answered Aug 10 '26 16:08

Marcus S. Zarra


An alternative to the CLI tool mentioned by Marcus Zarra is to create a full GUI Mac app. With Cocoa bindings this is very straightforward, and will give you a visual editor for your pre-packaged database as well.

I've written about this concept here and there is an example project on GitHub which contains both Mac and iOS apps.

like image 31
jrturton Avatar answered Aug 10 '26 16:08

jrturton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!