FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

Core Data: Wrap up

Paul Hudson    @twostraws   

Core Data might seem like a dry topic at first, but it’s so useful when building apps – you’ve seen how it can add, delete, sort, filter, and more, all with relatively simple code. Yes, a few parts are a little murky in Swift – NSPredicate, for example, could do with some refinement, and NSSet is never pleasant to deal with – but with a little work on our behalf this stops being a problem.

Perhaps the most important thing about Core Data is that it’s guaranteed to be there for all apps, on all of Apple’s platforms. This means you can use it regardless of your needs: maybe it’s for saving important data, maybe it’s just a cache of content you downloaded; it doesn’t matter, because Core Data will do a great job of managing it for you.

Review what you learned

Anyone can sit through a tutorial, but it takes actual work to remember what was taught. It’s my job to make sure you take as much from these tutorials as possible, so I’ve prepared a short review to help you check your learning.

Click here to review what you learned in this project.


One of the best ways to learn is to write your own code as often as possible, so here are three ways you should try extending this app to make sure you fully understand what’s going on.

All three of these tasks require you to modify the FilteredList view we made:

  1. Make it accept an array of NSSortDescriptor objects to get used in its fetch request.
  2. Make it accept a string parameter that controls which predicate is applied. You can use Swift’s string interpolation to place this in the predicate.
  3. Modify the predicate string parameter to be an enum such as .beginsWith, then make that enum get resolved to a string inside the initializer.
Hacking with Swift is sponsored by Stream

SPONSORED Stream’s latest iOS Chat SDK release provides a better developer experience with new docs, customizable attachments, and UI components, and under-the-hood performance improvements.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Buy Pro Swift Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift (Vapor Edition) Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Server-Side Swift (Kitura Edition) Buy Beyond Code

Was this page useful? Let us know!

Average rating: 4.9/5

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.