Created
March 25, 2020 16:46
-
-
Save arpitdsoni/8f1e588f9acbe8df6cdaa5aba797f36b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol SafeValueForKeyPath {} | |
extension SafeValueForKeyPath where Self: CFXManagedObject { | |
func safeValueForKeyPath<Value>(_ keyPath: KeyPath<Self, Value?>) -> Value? { | |
let keyPathStr = NSExpression(forKeyPath: keyPath).keyPath | |
return managedObjectContext?.performAndWait { | |
return value(forKeyPath: keyPathStr) as? Value | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment