Core Data Fundamentals

This course demonstrates the fundamental techniques needed to effectively use Core Data to store and manage data in your apps.
Course info
Rating
(127)
Level
Intermediate
Updated
Dec 11, 2013
Duration
2h 33m
Table of contents
Description
Course info
Rating
(127)
Level
Intermediate
Updated
Dec 11, 2013
Duration
2h 33m
Description

This course demonstrates the fundamental techniques needed to effectively use Core Data to store and manage data in your apps. You'll learn the role of each class in the Core Data stack. You'll see how you can quickly and easily define a data model using the tools available in Xcode. Reading and writing data to the model will be covered along with a discussion about how to build sophisticated queries. The NSFetchedResultsController pairs nicely with the UITableView to present data from a Core Data model and you'll see how to use it in your apps. You'll also learn how to version a Core Data model so that data migrations for subsequent versions of your app are simple to implement. The last module will focus on performance tips and tricks and how you can make sure your app works with your data model as efficiently as possible.

About the author
About the author

Brice has been a professional developer for over 20 years and loves to experiment with new tools and technologies. Web development and native iOS apps currently occupy most of his time.

More from the author
State of .NET: Executive Briefing
Beginner
25m
May 17, 2019
RxJS: The Big Picture
Beginner
1h 2m
Mar 5, 2019
More courses by Brice Wilson
Section Introduction Transcripts
Section Introduction Transcripts

Introduction and Overview of Core Data
Hi, this is Brice Wilson with Pluralsight. Welcome to this course titled, Core Data Fundamentals. Core Data is a very popular and powerful data management framework that is the perfect answer for many data storage problems. It's not the answer for every data problem, but the breadth and scale of Core Data make it a technology that every iOS developer should at least be familiar with. In this course, you'll learn everything you need to know to get started managing data in your apps with Core Data.

Creating a Model
Hi, this is Brice Wilson. Welcome back to this course on Core Data Fundamentals. In this module, we're going to take a close look at how to create a Core Data model. The model is a starting point for working with Core Data and we'll take a look at the different parts of a model and the tools in Xcode that help you create them. We'll start by talking about entities. They're the centerpieces of any model. They represent the things you plan to store. Each entity is composed of a set of attributes that describe the properties of the entity. We'll see how to create attributes and how to set their data type, validation rules, and other properties that will help you ensure you maintain a high level of data integrity. Since entities represent real world objects, they will have relationships to other entities. Those relationships can also be defined in the model. We'll look at the different types of relationships and how to configure them in the Xcode model designer. And speaking of the model designer, we'll take a close look at the model designer in Xcode and the various ways you can design and configure these components when creating your model. Let's get started talking about entities.

Basic Reading and Writing
Hi, this is Brice Wilson. Welcome back to this course on Core Data Fundamentals. In this module, we're going to cover how to configure the Core Data Stack in your code and go over the absolute basics you need to know to read and write data using Core Data. Let's get started. We'll start by reviewing the objects that make up the Core Data Stack and then see how to configure them in our app. We'll then take a look at the NSEntityDescription class and the role it plays in creating new data in our persistent store. Instances of the NSManagedObject will hold the actual entity data we read and write, so we'll see how to use it when creating and retrieving data. Once our data is saved to our persistent store, we'll use an instance of NSFetchRequest to retrieve it. We'll see a simple example of how to do that as well.

Beyond the Basics: More Reading and Writing
Hi, this is Brice Wilson. Welcome back to this course on Core Data Fundamentals. In this module, we're going to cover how to configure custom classes for the entities in our model, and look at some new techniques for reading and writing data. We're going to start this module by seeing how to create custom classes for the entities in our model. Once we have those created, we can do all of our reading and writing with them instead of the default NSManagedObject class. We'll also see how to initialize new Core Data objects, as well as those being retrieved from the persistent store. Since the objects are being managed by Core Data, the normal initialization rules don't apply. We'll look at some more sophisticated techniques for reading and writing data that account for the relationships defined in the model. Finally, we'll see how to refine the queries we create using NSFetchRequest by using NSPredicates to filter the data being returned. Let's get started by creating some custom classes for our entities.

Using NSFetchedResultsController
Hi, this is Brice Wilson. Welcome back to this course on Core Data Fundamentals. In this module, we're going to see how to use the NSFetchedResultsController to easily display data from Core Data in our apps. Before I can even talk about what we'll cover in this module, I think it would be helpful to give at least a quick overview of the NSFetchResultsController and the purpose it serves when working with Core Data. In a nutshell, it's a class that abstracts away the details of displaying data from a Core Data store in a UITableView and also monitoring the data for changes and propagating those changes back to the UITableView. You could certainly display data from a Core Data store in a TableView without using an NSFetchedResultsController, but you would most likely end up writing a lot of code to do many of the same things you could have gotten for free by just wiring your TableView up to the FetchedResultsController in the first place. We're going to see how to create a new NSFetchedResultsController and how to use it to retrieve data and wire it to a UITableView. We'll also see how to retrieve the data so that it can be easily displayed in sections in the TableView and how to implement the methods of the UITableViewDataSource protocol to use the data provided by the NSFetchedResultsController to properly format those sections. The FetchedResultsController's best trick is its ability to monitor the DataContext for changes to the data and automatically update the related TableView with those changes. To say this takes place automatically is a slight exaggeration. It does require us to write a few lines of code, but it's very straight forward and is nowhere near the amount of code you would write if you attempted to implement the same functionality on your own.

Performance Tips and Tricks
Hi, this is Brice Wilson with Pluralsight. Welcome back. In the final module of this course, we're going to cover some tips and tricks you can use to make sure Core Data is configured for optimal performance. Tuning database performance, whether it's on a giant enterprise-class database or the SQLite store in your Core Data implementation, is very specific to the type of data you're storing, the structure of the data, and how the data will be queried. However, there are a number of very general best practices you can follow that may give you the performance you need without having to resort to more granular database-specific tuning options. In this module, I'll focus on those general options that give you huge performance returns for relatively little effort. We'll start by talking about some simple changes you can implement in your model. By just checking a few boxes and modifying a couple of settings in the model designer, you can significantly boost performance. Next, we'll look at some fetch techniques to make sure the queries you run against the model are as fast as possible. I'll briefly comment on how to get started with Core Data concurrency, in case you determine your app can benefit from the use of multiple threads. Finally, I'll demonstrate an Xcode setting that allows you to view the SQL that is generated and sent to the SQLite database and I'll use the instruments profiling tool that ships with Xcode to analyze the performance of our Core Data queries. Let's get started with the model.