You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -262,6 +263,19 @@ You must set the DataStack into a view's environment using the `dataStackEnviron
262
263
263
264
# CRUD Helpers
264
265
266
+
### Typed NSManagedObjectID
267
+
268
+
Use `TypedObjectID` in place of `NSManagedObjectID` anywhere that you want to enforce type safety around the ID. Because both `NSManagedObjectID` and the `TypedObjectID` wrapper are `Sendable`, they are the best way to send references to `NSManagedObject` between contexts.
269
+
```swift
270
+
let viewContextPerson =Person(...) // get a person on the ViewContext
271
+
let personId =TypedObjectID(viewContextPerson.objectID) // personId refers only to Person type
272
+
273
+
try backgroundContext.perform {
274
+
// get a reference to the same Person from storage, but safe for this context:
275
+
let backgroundContextPerson =try backgroundContext.existingObject(with: personId)
276
+
}
277
+
```
278
+
265
279
### Updatable Protocol
266
280
267
281
Add the `Updatable` protocol to your Model types to get some free functions. Protocol conformance has no requirements except that the implementing type is a `NSManagedObject` subclass.
0 commit comments