Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Core Data for Storage - in navigation based & window based application - iPhone

There are too many options for creating projects in XCode,

But When we select Navigation Based Application / Window based Application

We can see the extra option - Use Core Data For Storage.

I need brief detail about it.

What's new in it?

like image 629
Sagar Kothari Avatar asked Aug 27 '09 21:08

Sagar Kothari


People also ask

What should Core Data be used for?

Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.

Where does Core Data store data?

The persistent store should be located in the AppData > Library > Application Support directory. In this example you should see a SQLite database with extension . sqlite. It is possible that you don't see the persistent store in the Application Support directory.

Should I use Core Data or realm?

Core Data is incredibly fast if you consider what it does under the hood to do its magic. But Realm is faster, much faster. Realm was built with performance in mind and that shows. As Marcus Zarra once said in a presentation, you don't choose Core Data for its speed.


1 Answers

To elaborate on what Jergason wrote. Core Data is an Object-Relational Mapping (ORM) similar to Hibernate in the Java world. It abstracts the actual mechanics of storing data (such as SQL or .plist files) away from your code. Your code just needs to deal with a consistent object oriented framework to fetch objects, update them and persist them. Core Data supports some level of ACID transactions, but not 2-Phase commits. On the iPhone, the default settings for Core Data wrap the sqlite databases with the ORM layer.

One of the interesting side benefits of using Core Data is the tool to visually design your data model and to generate the model classes. If you have a large model this can save alot of time in hand coding model classes.

Another interesting benefit of Core Data is it's ability to migrate your database from one model version to another. This is very important in the iPhone world since you may want to modify your data model from one version of your app to the next. Core Data provides a pretty straightforward way to migrate the persisted data from the old model to the new without you having to write a ton of migration code. You just define a migration map and add a 'few' lines of code to your app delegate and things get converted for you.

Core Data on the iPhone is designed for the mobile environment. If you fetch all the rows in a table into an array it doesn't actually pull everything into memory. It creates what Apple calls a faulting array which is just an object that looks like an NSArray. When you access the various elements of the array Core Data fetches those entities (rows) on use, not on query. It saves memory and helps your app run faster.

All-in-all it's a pretty full featured ORM layer, not as rich as Hibernate, but sufficient for this environment.

like image 139
Jack Cox Avatar answered Nov 16 '22 01:11

Jack Cox