diff --git a/AltStore/Types/Managed.swift b/AltStore/Types/Managed.swift index ead14494..177d5774 100644 --- a/AltStore/Types/Managed.swift +++ b/AltStore/Types/Managed.swift @@ -50,4 +50,23 @@ struct Managed return result } + + // Optionals + subscript(dynamicMember keyPath: KeyPath) -> T? where ManagedObject == Optional + { + 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 + } }