Release: P2. Geared toward intermediate to advanced developers, this book gets you comfortable with the basics of Core Data. Learn how to reduce your number of mapping models, integrate your Core Data app with Spotlight and Quick Look, connect your application with sync services, and find out how to use Core Data in a multithreaded environment. Why do developers need to know it? By learning and using Core Data, you can save yourself a significant amount of development time on every application you build. In some cases, you can save as much as 30 percent of the application development time by using Core Data.
|Published (Last):||21 October 2018|
|PDF File Size:||5.9 Mb|
|ePub File Size:||10.2 Mb|
|Price:||Free* [*Free Regsitration Required]|
Unfortunately, that read led to this post as I disagree strongly with a number of the laws he has laid down. Do not use Core Data as if it were a database No disagreement; Core Data is your object model and it can persist to a database but that is not its biggest strength. Core Data is your object model, not a thin wrapper around a database. It is a scratchpad. It is where you stage changes to the data objects and decide to persist them or not.
I have advocated putting an object around it for convenience and Apple added the NSPersistentContainer which is designed to be subclassed. That wrapper is a great place to handle migrations, importing, exporting, convenience methods for accessing data; the list goes on.
All of the internal workings of your Core Data stack, your persistence and data model absolutely should be stored in the persistent container and that container should be injected through your controllers in your application. As with ANY object, assume it is thread locked unless you can demonstrably confirm that it is safe to use across threads. NSManagedObject instances are your data objects and should be treated as such.
If your app talks to anything else then you will want to use parent-child contexts. The parent context should be on the user interface thread the main thread and when you need to do asynchronous work with your data objects importing or exporting then you want to do that on another thread and that work should be done in a child context. A child context simplifies the transfer of notifications of data changes and greatly simplifies using Core Data in a multi-threaded environment.
Keep your main queue context read-only The main queue is also known as the user interface queue. The context that is associated with that queue should be for the user. That context reads and writes data when the user is interacting with the application.
Should it be read-only? Absolutely not. Should it be user-only? Any non-user work importing and exporting should be done on a child context on a background thread see response to 6 above.
Use an abstraction layer Please do not do this. You are going to make the next developer curse your name in a very unpleasant manner. Use Core Data in your user interface. Do not create dummy data objects on top of Core Data. That leads to a maintenance nightmare. Your user interface can use Core Data without really knowing that it is using Core Data.
Your user interface treats the NSManagedObject instances as if they were data objects because they are data objects. Your user interface does not need to know any more about Core Data than it does for any other model structure. Your user interface should talk to your persistent container subclass and ask for the data it needs.
The response to that request might be instances of NSManagedObject or might be an NSFetchedResultsController which then serves up the data objects in a consistent and reliable way. Use Core Data as a local cache I agree with the wording of this rule but I suspect the meaning is different. Core Data, like any local persistence, is a local cache of what is on the server. This is not specific to Core Data because that is what any local persistence does when you have data on a server.
Core Data is more than just a local cache. Core Data is not complicated Core Data is as complicated as you make it. Most of the time you do not need or want the advanced features of Core Data and can just grab an instance of NSPersistentContainer and be happy. When you need to deal with more complicated or interesting situations there is a fair chance that Core Data has an advanced feature to handle that situation. The harder your code is to write the harder it is going to be to maintain and debug.
Keep it simple.
Core Data (2nd edition): Data Storage and Management for iOS, OS X, and iCloud
Zarra The Pragmatic Bookshelf, January has recently received a major update. Whilst it is still a great book it was starting to get a little dated. This was not such a huge problem as many of the key concepts are valid for both platforms. The second edition has been substantially updated and the change in emphasis is evident from the change in subtitles of the two editions. The growing army of iOS developers has had an impact: The largest number of Objective-C developers develop only for iOS, and therefore we will keep our focus there.
Core Data in Objective-C
Unfortunately, that read led to this post as I disagree strongly with a number of the laws he has laid down. Do not use Core Data as if it were a database No disagreement; Core Data is your object model and it can persist to a database but that is not its biggest strength. Core Data is your object model, not a thin wrapper around a database. It is a scratchpad.