From 198be73f14a3388457065e5f2113b513cb9fa994 Mon Sep 17 00:00:00 2001 From: Will Jessop Date: Thu, 29 Dec 2022 20:27:30 -0500 Subject: [PATCH] Updated readme --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a384062..b3dedf2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Lightweight Active-record-ish pattern. - [Installation](#installation) - [Example App](#example-app) - [Documentation](#documentation) + - [Predicate](#predicate) + - [`NSManagedObject` Extensions](#nsmanagedobject-extensions) - [Logging](#logging) - [Quick Start with SwiftUI](#quick-start-with-swiftui) @@ -64,9 +66,21 @@ Instead of NSPredicate(format:"color = %@ and city = %@", argumentArray:["Blue", city]) ``` +### `empty()` +Returns a new, non-nil, `NSPredicate` object that will match every single row in the database. -## 'NSManagedObject' Extensions +> This is especially helpful with: +> 1. The [@FetchRequest property wrapper](https://developer.apple.com/documentation/swiftui/fetchrequest). Using a nil predicate can cause unexpected behavior if you dynamically assign or edit the predicate at runtime. +> 2. Other Core Data quirks around nil predicates and updating when you do fancy stuff. +> +> Before: `@FetchRequest(sortDescriptors: [], predicate: nil)` +> After: `@FetchRequest(sortDescriptors: [], predicate: Predicate.empty())` + + + + +## `NSManagedObject` Extensions ### `findOrCreate` Finds an instance of the `NSManagedObject` that has a column (property) matching the passed value. If it doesn't exist in the database, creates one, and returns it.