mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 14:53:25 +01:00
Supports optional @Managed properties
This commit is contained in:
@@ -50,4 +50,23 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user