Supports optional @Managed properties

This commit is contained in:
nythepegasus
2024-05-09 00:33:29 -04:00
committed by ny
parent dd0436511a
commit bbf712a822

View File

@@ -50,4 +50,18 @@ struct Managed<ManagedObject>
return result
}
// Optionals
subscript<Wrapped, T>(dynamicMember keyPath: KeyPath<Wrapped, T>) -> T? where ManagedObject == Optional<Wrapped> {
var result: T?
if let context = self.managedObjectContext {
context.performAndWait {
result = self.wrappedValue?[keyPath: keyPath] as? T
}
} else {
result = self.wrappedValue?[keyPath: keyPath] as? T
}
return result
}
}