From ac8fb8851fe3fd4922ab43cb44149849fc20ceea Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 15 Nov 2022 16:52:17 -0600 Subject: [PATCH] Supports optional @Managed properties --- AltStore/Types/Managed.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 + } }