Search

Showing the first 50 of 85 results for "core data"

Why I Chose Core Data Over SwiftData for Hive Notes

Why I Chose Core Data Over SwiftData for Hive Notes

SwiftData is Apple's modern take on local persistence. It has a cleaner syntax, tighter SwiftUI integration, and less boilerplate. Core Data is the two-decade-old workhorse. For Hive Notes and its 15-entity data model, I needed reliability over novelty. Sometimes boring technology is exactly what you need.

in Core Data

8:34

Seeding Data Asynchronously

Seeding Data Asynchronously

Seeding a Core Data Persistent Store

We successfully seeded the Core Data persistent store with hard-coded seed data in the previous episode. While the implementation works fine, it isn't perfect. Seeding the persistent store takes place on the main thread. We invoke the seed() method in the viewDidLoad() method of the NotesViewController class and we insert the managed objects into the main managed object context of the Core Data manager.

in Core Data

9:52

Hard-Coding Seed Data

Hard-Coding Seed Data

Seeding a Core Data Persistent Store

Seeding a Core Data persistent store with hard-coded seed data is fast and easy. The application we'll be seeding with data in this episode is Notes, the application we build in Core Data Fundamentals. Download the starter project of this episode if you'd like to follow along.

in Core Data

8:43

Type Methods

Type Methods

Fetching Records With Core Data

Developers often complain that Core Data has an arcane syntax and complicated API. "It's tedious to work with Core Data." seems to be the general consensus. It's true that Core Data used to be difficult to use and the framework's syntax wasn't as elegant as it could be. That's something of the past, though. The more Core Data matures, the more I enjoy and appreciate the framework. First impressions are difficult to change and it's therefore unsurprising that developers often fall back to third party libraries. Using a third party library to interact with a first party framework isn't something I recommend. Many of us find fetching records from a persistent store to be clunky and tedious. Is that true? In this series, I'd like to show you how easy and elegant fetching records from a persistent store can be.

in Core Data

5:06

Writing More Unit Tests

Writing More Unit Tests

Unit Testing Core Data Models

It's time to shift gears and focus on the Category class. This shouldn't be difficult since you already know how to write unit tests for a Core Data model and we laid the foundation when we implemented the unit tests for the Note class. Pause the episode for a moment and give it a try.

in Core Data

5:59

Unit Testing a Core Data Model

Unit Testing a Core Data Model

Unit Testing Core Data Models

It's time to write the first unit test for the Note class. The first unit test we write tests the updatedAtAsDate computed property of the Note class. Remember that we only unit test the behavior we add to the Note class. We name the unit test testUpdatedAtAsDate()

in Core Data

4:11

Setting Up the Project

Setting Up the Project

Unit Testing Core Data Models

In this series, I show you how to unit test Core Data models. Before we start, though, I'd like to challenge you. How would you unit test a Core Data model? Pause the video for a moment and try to come up with a strategy. Remember what we covered in Core Data Fundamentals. Which ingredients do we need to create an NSManagedObject instance?

in Core Data

4:27

Where to Go From Here

Where to Go From Here

Core Data Fundamentals

My hope is that this series has taught you that Core Data isn't as difficult as many developers believe it to be. Core Data isn't complex once you understand how the various pieces of the framework fit together.

in Core Data

6:43

Data Model Migrations

Data Model Migrations

Core Data Fundamentals

An application that grows and gains features also gains new requirements. The data model, for example, grows and changes. Core Data handles changes pretty well as long as you play by the rules of the framework.

in Core Data

6:13

Exploring the NSFetchedResultsControllerDelegate Protocol

Exploring the NSFetchedResultsControllerDelegate Protocol

Core Data Fundamentals

To update the table view, we listened for notifications sent by the managed object context of the Core Data manager. This is a perfectly fine solution. But it can be messy to sift through the managed objects contained in the userInfo dictionary of the notification. In a complex Core Data application, the NSManagedObjectContextObjectsDidChange notification is sent very frequently. It includes every change of every managed object, even the ones we may not be interested in. We need to make sure we only respond to the changes of the managed objects we are interested in.

in Core Data

8:44

Working With Managed Objects

Working With Managed Objects

Core Data Fundamentals

Core Data records are represented by the NSManagedObject class, a key class of the framework. In this episode, you learn how to create a managed object, what classes are involved, and how a managed object is saved to a persistent store.

in Core Data

3:13

Core Data and Dependency Injection

Core Data and Dependency Injection

Core Data Fundamentals

I'm not going to lie. I don't like singletons. Singletons are fine if they're used correctly, but I don't like singletons for convenience. They almost always lead to problems down the line. This means that the Core Data manager isn't going to be a singleton.

in Core Data

8:31

Setting Up the Core Data Stack

Setting Up the Core Data Stack

Core Data Fundamentals

It's time to write some code. Had we checked the Use Core Data checkbox during the setup of the project, Xcode would have put the code for the Core Data stack in the application delegate. This is something I don't like and we won't be cluttering the application delegate with the setup of the Core Data stack.

in Core Data

1:49

Building Notes

Building Notes

Core Data Fundamentals

Notes is a simple application for iOS that manages a list of notes. It's a fine case study to teach you the fundamentals of the Core Data framework. In this episode, I'd like to show you what Notes is capable of.

in Core Data

5:08

What Is Core Data

What Is Core Data

Core Data Fundamentals

Developers new to Core Data usually don't take the time to learn the framework. Not knowing what Core Data is, makes it hard and frustrating to wrap your head around the ins and outs of the framework. I'd like to start by spending a few minutes exploring the nature of Core Data and, more important, explain to you what Core Data is and isn't.

in Core Data

3:08

Welcome to Core Data Fundamentals

Welcome to Core Data Fundamentals

Core Data Fundamentals

Welcome to Core Data Fundamentals. In this series, you'll learn the ins and outs of Apple's popular Core Data framework. Even though we'll be building an iOS application, the Core Data framework is available on iOS, tvOS, macOS, and watchOS, and the contents of this series apply to each of these platforms.

in Core Data

Fetching Records With Core Data: Type Methods

Fetching Records With Core Data: Type Methods

Fetching Records With Core Data

Developers often complain that Core Data has an arcane syntax and a complicated API. "It's tedious to work with Core Data." seems to be the general consensus. It's true that Core Data used to be difficult to use and the framework's syntax wasn't as elegant as it could be. That's something of the past, though. The more Core Data matures, the more I enjoy and appreciate the framework.

in Core Data

Don’t Use a Core Data Library

Don’t Use a Core Data Library

Core Data is a fantastic framework and I love using it. I agree that Core Data has a learning curve, but isn't this true for many other frameworks? Because of Core Data's learning curve, developers often turn to third party libraries that make working with the framework easier.

in Core Data

The Elegance of Disposable Managed Object Contexts

The Elegance of Disposable Managed Object Contexts

In Core Data Beyond the Basics, we work with an application that manages clients and their invoices. I named the application Invoices. What's in a name? The application is similar to, for example, the mobile application of FreshBooks.

in Core Data

An Introductory Core Data Tutorial

An Introductory Core Data Tutorial

If you're reading this, then I assume you are new to Core Data. You may have heard about Core Data and you'd like to find out whether it's a good fit for you or the project you're working on. If this description fits you, then take a seat. This Core Data tutorial teaches you everything you need to know to better understand what Core Data is and isn't.

in Core Data

More Core Data and Concurrency

More Core Data and Concurrency

In the previous tutorial, we discussed Core Data in the light of concurrency. I hope that lesson has taught you that Core Data and concurrency can go hand in hand. As long as you remember the basic rules we discussed, you should be fine.

in Core Data

Core Data and Concurrency

Core Data and Concurrency

Up to now, we've used a single managed object context, which we created in the CoreDataManager class. This works fine, but there will be times when one managed object context won't suffice.

in Core Data

Managing Records With Fetched Results Controllers

Managing Records With Fetched Results Controllers

The NSFetchedResultsController class isn't an essential component of a Core Data application, but it makes working with collections of managed objects much easier. This tutorial introduces you to the, almost magical, NSFetchedResultsController class.

in Core Data

Migrating a Data Model With Core Data

Migrating a Data Model With Core Data

An application that grows and gains features also gains new requirements. The data model, for example, grows and changes. Core Data handles changes pretty well as long as you play by the rules of the framework.

in Core Data

More Fetching and Deleting Managed Objects With Core Data

More Fetching and Deleting Managed Objects With Core Data

The final piece of the CRUD puzzle covers deleting records from a persistent store. I can assure you that deleting records is no rocket science. We also take a closer look at the NSFetchRequest class. In the previous tutorial, we used this class to fetch the records of an entity. But NSFetchRequest has a lot more to offer.

in Core Data

Reading and Updating Managed Objects With Core Data

Reading and Updating Managed Objects With Core Data

In the previous tutorial, we created a list record and pushed it to the persistent store by saving its managed object context. The persistent store coordinator handled the nitty-gritty details of inserting the list record into the persistent store. This tutorial focuses on reading and updating records.

in Core Data

Working With Managed Objects In Core Data

Working With Managed Objects In Core Data

In this tutorial, we take a look at the NSManagedObject class, a key class of the Core Data framework. You learn how to create a managed object, what classes are involved, and how a managed object is saved to a persistent store.

in Core Data

Data Model, Entities, and Attributes

Data Model, Entities, and Attributes

The data model is a key component of the Core Data stack and an integral part of every Core Data application. In this tutorial, we explore the data model and learn about entities and attributes.

in Core Data

Setting Up the Core Data Stack From Scratch

Setting Up the Core Data Stack From Scratch

In the previous tutorial, we set up a Core Data stack using the NSPersistentContainer class. While this is convenient, it teaches you very little about the Core Data stack and how to set one up from scratch. In this lesson, we create a Core Data stack without relying on Xcode's Core Data template.

in Core Data

Exploring the Core Data Stack

Exploring the Core Data Stack

If you dipped your toe in iOS or macOS development, then you've probably heard about Core Data. Core Data is Apple's framework for managing and persisting an object graph. It was introduced in 2005, alongside the release of Mac OS X Tiger. On iOS, the framework has been available since iPhone OS 3.0.

in Core Data

Three Features of NSManagedObject You May Not Know About

Three Features of NSManagedObject You May Not Know About

NSManagedObject is the class you interact with most when you work with Core Data. The class may appear as a glorified dictionary, but it is much more than that. In this tutorial, I show you three features of the NSManagedObject class you may not know about.

in Core Data

Exploring the NSPersistentStoreDescription Class

Exploring the NSPersistentStoreDescription Class

Core Data received an important update during this year's WWDC. We already explored the addition the of the NSPersistentContainer class and Xcode's improved support for Core Data. But there are several more subtle additions and enhancements worth exploring, such as the NSPersistentStoreDescription class. That is the focus of this tutorial.

in Core Data

What Are Core Data Query Generations

What Are Core Data Query Generations

Earlier this month, I wrote about Core Data faults. Faulting is a key concept of the Core Data framework. It is because of faulting that Core Data is as performant as it is and it ensures Core Data's memory footprint remains at an acceptable level.

in Core Data

Three Common Core Data Mistakes to Avoid

Three Common Core Data Mistakes to Avoid

Developers familiar with Core Data don't consider the framework difficult or hard to work with. If you respect the rules of the framework, Core Data won't surprise you. But that is often the problem. Developers make mistakes because they violate a rule they don't know about. In this article, I discuss three common mistakes developers make working with Core Data.

in Core Data

How to Learn Core Data

How to Learn Core Data

Core Data is one of the most misunderstood frameworks available on iOS, tvOS, macOS, and watchOS. And that is unfortunate because it is a fantastic piece of software engineering. But why is it misunderstood?

in Core Data