Professional Documents
Culture Documents
Related Resources
Store
Articles
Blogs
By Tim Roadley
$31.99
Page 1 of 1
$25.59
! Buy
iOS Internationalization:
The Complete Guide
By Shawn E. Larson
$19.99
Also Known As
What is it?
Managed Object
Model
The Model,
Data Model,
Schema or Object Graph
Persistent Store
The Store
or Database
Managed Object
Managed Object
Context
The Context, or
MOC
Persistent Store
Coordinator
The Coordinator
Entity
Attribute
A property of an Entity.
Relationship
Joins Entities.
Fetch Request
Predicate
Sort Descriptor
Filter
A way of limiting the managed objects that a Fetch Request will return.
A way of ordering the managed objects that a Fetch Request will return.
There are plenty more terms youll come across, however those are the fundamental ones to focus on first.
The Task entity contains a name and subtask_name attribute. When a managed
object is created from this Task entity, it will have a name and subtask_name
property. Without relationships, this data model supports only one subtask. Now
consider the following entities:
The line with the double-headed arrow indicates a to-many relationship from the
Task entity to the Subtask entity. This means that a task can now have multiple
subtasks, not to mention that reference to the parent task can be obtained
through the inverse relationship! This flexibility is not only more convenient, but
also saves space in the database because the parent task name only has to be
stored once.
If you wanted to get really advanced and enable support for tasks to have subtasks of subtasks, what then? Consider the re-architected Task entity below:
The model now supports an unlimited depth of subtasks because the Task entity
is related to itself!
The scalability and flexibility of Core Data is only scratching the surface of its benefits. Core Data not only leverages the benefits of a relational database, you dont
even have to write any SQL to use it! Core Data takes on that responsibility for
you, and optimizes the generated SQL for you automatically. I havent even begun
to dive into the myriad of the other value-add that you get for free, such as model
versioning, migration, validation, change management and iCloud synchronization, to name a few. If theres any iOS framework thats worth investing your time
"The model used to open the store is incompatible with the one used to create the
store."
When you create a persistent store, it is based on a specific managed object model. If the structure of the model ever changes, then the persistent store must be
updated to match. If you dont do this, the store will be incompatible and wont
open anymore. If your customers are using stores based on a model you have
since edited without versioning, your app is destined to crash. To ensure the model migration process works, you need to ensure youre careful to add a model version before editing the model. As a side note, some changes such as attribute defaults, validation rules, and fetch request templates can be modified without consequence.
Conclusion
If theres any iOS framework thats worth investing your time in, its Core Data.
Knowing this solid technology pays dividends, and once youve picked it up youll
never look back. If youre interested in learning Core Data, consider my new book,
Learning Core Data for iOS. This iOS 7 based book takes you on the complete
journey from knowing nothing about Core Data to producing Grocery Dude,
which is available for free on the App Store today. Everything is explained in succinct detail so you can apply what youve learned straight away. Ive put a chapter
summary up here. Happy coding!
Learn More
Learn More
Learn More
Page 1 of 1
Discussions