Skip to content

Instantly share code, notes, and snippets.

@PetreVane
Last active January 24, 2020 17:25
Show Gist options
  • Save PetreVane/078a03f3b3c7bb0cbc27a71a3b81d829 to your computer and use it in GitHub Desktop.
Save PetreVane/078a03f3b3c7bb0cbc27a71a3b81d829 to your computer and use it in GitHub Desktop.
Remember to save UserInfo to fileManager, before attempting to retrieve any data
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