Tim Roadley

Learning Core Data for iOS with Swift

Use CloudKit to build this shared-list Groceries App

Groceries

Chapter Summary

1 Your First Core Data Application
The groundwork is laid as the fundamental concepts of Core Data are introduced. You learn what Core Data is, and just as importantly, what it isn't. In addition, Core Data integration with an existing application is demonstrated as the CDHelper class is implemented.
2 Managed Object Model Basics
Data models are introduced as parallels are drawn between traditional database schema design and Core Data. You learn how to configure a basic managed object model as entities and attributes are discussed, along with accompanying advice on choosing the right data types. Inserting, fetching, filtering, sorting, and deleting managed objects are also covered and followed up with an introduction to fetch request templates.
3 Managed Object Model Migration
Experience lightweight migration, default migration, and using a migration manager to display migration progress. You learn how to make an informed decision when deciding between migration options for your own applications and become comfortable with the model-versioning capabilities of Core Data.
4 Managed Object Model Expansion
The true power of a relational data model is unlocked as different types of relationships are explained and added to Groceries. Other model features such as abstract and parent entities are also covered, along with techniques for dealing with data validation errors.
5 Table Views
The application really comes to life as Core Data is used to drive memory-efficient and highly performing table views with a fetched results controller. Of course, most of the generic legwork is put into a reusable table view controller subclass called CDTableViewController. By dropping this class into your own applications, you can easily deploy Core Data-driven table views yourself.
6 Views
Working with managed objects takes a front seat as you're shown how to pass them around the application. Objects selected on a table view are passed to a second view, ready for editing. The editing interface is added to Groceries, demonstrating how to work with objects and then save them back to the persistent store.
7 Picker Views
As a nice touch, Core Data-driven picker views are added to the editing views. Picker views allow the user to quickly assign existing items to a unit of measurement, home location, or shop location. A special reusable text field subclass called CDPickerTextField is introduced, which replaces the keyboard with a Core Data picker view whenever an associated text field is tapped.
8 Preloading Data
Techniques for generating a persistent store full of default data from XML are explained and demonstrated in this chapter as the generic CDImporter helper class is introduced. Once you have a persistent store to include with a shipping application, you then see how to determine whether a default data import is required or even desired by the user.
9 Deep Copy
A highly flexible and fine-grained alternative to migratePersistentStore, deep copy enables you to copy objects and relationships from selected entities between persistent stores. In this chapter, the CDImporter helper class is enhanced with the deep copy capability.
10 Performance
Gain experience with Instruments as you identify and eliminate performance issues caused by the common pitfalls of a Core Data application. The camera functionality is introduced to highlight these issues and demonstrates just how important good model design is to a well-performing application.
11 Background Processing
Top-notch performance requires intensive tasks be offloaded to a background thread. You learn just how easy it is to run processes in the background as the example of photo thumbnail generation is added with a generic helper class called CDThumbnailer. You also learn how to keep memory usage low with another helper class, called CDFaulter.
12 Search
This chapter shows you how to integrate a UISearchController with Core Data as you implement efficient search in CDTableViewController.
13 iCloud
Enjoy the easiest, most reliable Core Data integration with iCloud yet. You learn how to handle multiple accounts and varying preferences on using iCloud without missing a beat.
14 Taming iCloud
Take iCloud integration to the next level with entity-level seeding and unique object de-duplication. This chapter shows you how to emulate first-time iCloud use by resetting ubiquitous content globally, the right way.
15 CloudKit Sync: Uploading Objects
This chapter shows you how to leverage a public CloudKit database to keep a small data set synchronized across the devices of a group of iCloud users. Part 1 lays the foundation for synchronization as the capability to automatically upload new NSManagedObjects is added.
16 CloudKit Sync: Downloading Changes and Handling Deletions
The synchronization implementation is finalized as deletion support and the capability to download changed CloudKit records are added.
A Preparing the Groceries Application
Every (non-Core Data) step involved in preparing the starting-point application for Chapter 1 is documented here for completeness.
B Finalizing the Groceries Application
Every (non-Core Data) step involved in finalizing the application for the App Store is documented here for completeness.

Complete Source Code

Groceries-AfterAppendixA.zip
Groceries-AfterChapter01.zip
Groceries-AfterChapter02.zip
Groceries-AfterChapter03.zip
Groceries-AfterChapter04.zip
Groceries-AfterChapter05.zip
Groceries-AfterChapter06.zip
Groceries-AfterChapter07.zip
Groceries-AfterChapter08.zip
Groceries-AfterChapter09.zip
Groceries-AfterChapter10.zip
Groceries-AfterChapter11.zip
Groceries-AfterChapter12.zip
Groceries-AfterChapter13.zip
Groceries-AfterChapter14.zip
EZiCloud.zip
Groceries-AfterChapter15.zip
Groceries-AfterChapter16.zip
EZCloudKit.zip
Groceries-AfterAppendixB.zip
Generic Core Data Classes.zip

Purchase

You can purchase this book from Amazon, InformIT and iBooks

Learning Core Data for iOS

Chapter Summary

1 Your First Core Data Application
The groundwork is laid as the fundamental concepts of Core Data are introduced. You'll be shown what Core Data is, and just as importantly what it isn't. The first helper class "CoreDataHelper", is created as Core Data integration with an existing application is demonstrated with Grocery Dude.
2 Managed Object Model Basics
Data models are introduced as parallels are drawn between traditional database schema design and Core Data. You'll be shown how to configure a basic managed object model as entities and attributes are discussed, along with accompanying advice on choosing the right data types. Inserting, fetching, filtering, sorting and deleting managed objects is also covered and followed up with an introduction to fetch request templates.
3 Managed Object Model Migration
Experience lightweight migration, default migration, and using a migration manager to display migration progress. Learn how to make an informed decision when deciding between migration options for your own applications and become comfortable with the model versioning capabilities of Core Data.
4 Managed Object Model Expansion
The true power of a relational data model is unlocked as different types of relationships are explained and added to Grocery Dude. Other model features such as abstract and parent entities are also covered, along with techniques for dealing with data validation errors.
5 Table Views
The application really comes to life as Core Data is used to drive memory efficient and highly performing table-views using a fetched results controller. Of course, most of the generic legwork is put into a reusable table-view controller subclass called CoreDataTVC. By dropping this class into your own applications, you can easily deploy Core Data driven table-views yourself.
6 Views
Working with managed objects takes a front seat as you're shown how to pass them around the application. Objects selected on a table-view are passed to a second view ready for editing. The editing interface is added to Grocery Dude demonstrating how to work with objects and then save them back to the persistent store.
7 Picker Views
As a nice touch, Core Data driven picker-views are added to the editing views. Picker-views allow the user to quickly assign existing items to a unit of measurement, home location or shop location. A special reusable text-field subclass called CoreDataPickerTF is introduced, which replaces the keyboard with a Core Data picker-view whenever an associated text-field is tapped.
8 Pre-loading Data
Techniques for generating a persistent store full of default data from XML are explained and demonstrated in this chapter as the generic CoreDataImporter helper class is introduced. Once you have a persistent store to include with a shipping application, you'll then be shown how to determine whether a default data import is required or even desired by the user.
9 Deep Copy
A highly flexible and fine-grained alternative to migratePersistentStore, deep copy, allows you to copy objects and relationships from selected entities between persistent stores. In this chapter, the CoreDataImporter helper class is enhanced with the deep copy capability.
10 Performance
Gain experience with Instruments as you identify and eliminate performance issues caused by the common pitfalls of a Core Data application. The camera functionality is introduced to highlight these issues and demonstrates just how important good model design is to a well performing application.
11 Background Processing
Top-notch performance requires intensive tasks be offloaded to a background thread. Learn just how easy it is to run processes in the background as the example of photo thumbnail generation is added with the new generic helper class called Thumbnailer. Also learn how to keep memory usage low with another helper class, called Faulter.
12 Search
Learn how to handle twin fetched results controllers in the one table-view as you implement efficient search in CoreDataTVC.
13 Backup and Restore
Create backups and synchronize them to Dropbox using their Sync API. Restore data to any device using the same Dropbox account at the touch of a button.
14 iCloud
Enjoy the easiest, most reliable Core Data integration with iCloud yet. Handle multiple accounts and varying preferences on using iCloud without missing a beat.
15 Taming iCloud
Take iCloud integration to the next level with entity level seeding and unique object de-duplication. Accurately emulate first time iCloud use by resetting ubiquitous content globally, the right way.
16 Web Service Integration
Enable collaboration as cross-platform data sharing between multiple users is introduced with StackMob. StackMob have one of the best free Backend-as-a-Service (BaaS) offerings available, and their iOS API is native to Core Data.

Complete Source Code

GroceryDude-AfterAppendixA.zip
GroceryDude-AfterChapter01.zip
GroceryDude-AfterChapter02.zip
GroceryDude-AfterChapter03.zip
GroceryDude-AfterChapter04.zip
GroceryDude-AfterChapter05.zip
GroceryDude-AfterChapter06.zip
GroceryDude-AfterChapter07.zip
GroceryDude-AfterChapter08.zip
GroceryDude-AfterChapter09.zip
GroceryDude-AfterChapter10.zip
GroceryDude-AfterChapter11.zip
GroceryDude-AfterChapter12.zip
GroceryDude-AfterChapter13.zip
GroceryDude-AfterChapter14.zip
GroceryDude-AfterChapter15.zip
EasyiCloud.zip
Generic Core Data Classes.zip
GroceryCloud-AfterAppendixB.zip
GroceryCloud-AfterChapter16.zip

Purchase

You can purchase this book from Amazon, InformIT and iBooks
Email: timroadley@icloud.com | Twitter: @timroadley