From bbf712a822ed264b4a6bfd110470892c5d5f23ff Mon Sep 17 00:00:00 2001 From: nythepegasus Date: Thu, 9 May 2024 00:33:29 -0400 Subject: [PATCH] Supports optional @Managed properties --- AltStore/Types/Managed.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/AltStore/Types/Managed.swift b/AltStore/Types/Managed.swift index 425032f8..7d4a48a2 100644 --- a/AltStore/Types/Managed.swift +++ b/AltStore/Types/Managed.swift @@ -50,4 +50,18 @@ 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 + } }