Summary

This chapter was all about getting your feet wet with Core Data. You learned what the Core Data stack looks like and which parts are involved in using Core Data in your application. Even though the NSPersistentContainer object abstracts away a great deal of all of the complexity involved in the Core Data stack, it's still good to have a rough understanding of the parts that make up the Core Data stack.

After seeing this, you learned how to set up the Core Data stack and how you can use dependency injection to cleanly pass along the managed object context from the AppDelegate to the initial view controller. We used a protocol to mark view controllers that use a managed object so we don't have to check whether a certain object is of a certain class.

Then, you saw how to define your Core Data models and how to set up relationships between them. Doing this is made relatively simple in the editor because we can add properties by clicking on a plus icon. You saw that there's a range of options available to you when you add a new property but for a small application, such as the one we're building, most options can be set to their default values.

Finally, we took a look at generating our model classes. We saw three ways that Xcode allows us to create classes for our models: manually, automatically, and automatically as an extension. You saw a use case for each of the options and based on this, we'll continue to have Xcode generate all of our model classes.

The next chapter will show you how you can store new objects in the database and how you can fetch them using NSFetchRequest and NSFetchedResultsController. This will turn our app into a real application that makes use of a database. Let's not waste time and push right through to the next chapter!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.52.7