Created
November 24, 2017 17:30
-
-
Save PaulTaykalo/23b94c4f65df5084af4668dfa31b4bea to your computer and use it in GitHub Desktop.
Guards
This file contains hidden or 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
static func currentUser(inContext context: NSManagedObjectContext) -> User? { | |
guard let objectIdURL = UserDefaults.standard.url(forKey: userDefaultKeyUserURL) else { return nil } | |
guard let objectId = context.persistentStoreCoordinator?.managedObjectID(forURIRepresentation: objectIdURL) else { return nil } | |
var object: User? = nil | |
context.performAndWait { | |
object = context.object(with: objectId) as? User | |
} | |
return object | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment