Last active
January 24, 2020 17:25
-
-
Save PetreVane/078a03f3b3c7bb0cbc27a71a3b81d829 to your computer and use it in GitHub Desktop.
Remember to save UserInfo to fileManager, before attempting to retrieve any data
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
func retrieveUserInfo() throws -> User { | |
let plistDecoder = PropertyListDecoder() | |
let filePath = FileManager.documentsDirectory | |
let file = filePath.appendingPathComponent("SavedUserData").appendingPathExtension("plist") | |
guard let retrievedData = try? Data(contentsOf: file) else { print("Errors: \(Failure.missingFile.errorDescription)"); throw Failure.missingFile } | |
guard let decodedUserData = try? plistDecoder.decode(User.self, from: retrievedData) else { print("Error: \(Failure.failedDecodingFile.errorDescription)"); throw Failure.failedDecodingFile} | |
return decodedUserData | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment