Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m

Next lesson playing in 5 seconds


Free Preview: Get Started With Core Data


  • Overview
  • Transcript

Core Data is a very powerful framework for managing data, though it can be daunting to learn at first. It is hugely popular and well documented and has been around for years, both on iOS and OS X. The result is an easy-to-use framework for managing an object graph that is elegant to use and incredibly efficient in terms of memory usage.

In this course, Envato Tuts+ instructor Markus Mühlberger will show you how to use Core Data on iOS. You'll learn about the components of a Core Data stack, creating and manipulating data, relationships, filtering, and data migration. Along the way, you'll get to follow along as Markus builds a full-featured app for quiz masters, to create and edit quizzes.

Not up to speed with Swift yet? Watch our comprehensive course Up and Running With Swift 2 or check out these other Swift courses:

1. Introduction

1.1 Introduction

Core Data is a very popular and well documented framework for iOS and OS 10. Practically no application managing persistent data can work without it. Welcome to this Stuts Plus course, I am Markus Muhlberger and this is Get Started with Core Data. This framework has a steep learning curve and it can seem daunting at first but I'm going to take a step by step approach to introduce you to this topic, by also looking at more advanced real world usage patterns. In this course you will learn how to create the Core Data Stack, design your models, and also how to display and manipulate them. You will also learn about the different data types Core Data supports and how you can add your own custom types. We will also look at predicates to further the data. Finally, I'm going to show you how you can improve the performance of your app and what happens when your data model changes. During these lessons we will be creating a pop quiz utility app that can store quizzes and questions. When you are ready to get started, I will see you in the first lesson.

1.2 Project Overview

Hi and welcome back to Get Started with Core Data. In this lesson, I will show you the course project we are building and how the code and the repository is organized. The project is called Pop Quizzer. It is a utility app for quiz masters doing a quiz that has many questions and answers. You can create a new quiz and give it a name and the date when it is happening. The list gets sorted by newest first. You can also edit a quiz and delete it. Now a quiz can have multiple questions. For completeness sake, I added a detail view where you can see the question and answer. We don't really use it in the course, but the app has a few niceties I added and you can find them in the code yourself. Of course, you can also add questions, edit and delete them. We didn't completely implement the correct ordering when adding a new question. That's why the indexes are messed up. But, when you reorder them around a few times, it will have the correct sort order and updates as intended. I have prepared a project a little bit, for this course, so we don't have to do so much repetitive set up stuff, and can focus on the interesting things. In the first lesson for instance, we are going to create the qualitative stack. Here we also have the model file from the data model's lesson or the mapping from the migrations lesson. All the view controllers, including the table view controllers already exist in the project's template. And we will just complete the functionality. Apart from naming a few segues, you don't have to interact with the storyboard at all. It is a little bit hard to see at this resolution, but you hopefully can see and understand the connections between the fuse. For instance, the quiz tableview controller and the create pressview controller or questionsview controller. For the predicates lesson, I have created a special playground that spins up a special in memory Core Data stack. And here, you can experiment with the friends predicates to fetch cities and states from Core Data. As always, I have created separate commits for each lesson. The initial commit is the preparation work I have done, so you probably want to start from there. The last commit is the playground file that I added after I had finished the application already. Of course, each commit is also tagged with a lesson number. I hope you're excited to learn Core Data with this example project. And I will see you in the first lesson, where we will set up the heart of Core Data, the Core Data stack.