Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Created August 15, 2020 16:09
Show Gist options
  • Select an option

  • Save cipolleschi/b22333d947c46d7cef4870197153e956 to your computer and use it in GitHub Desktop.

Select an option

Save cipolleschi/b22333d947c46d7cef4870197153e956 to your computer and use it in GitHub Desktop.
func extractState() -> Models.User? {
guard
let state = UserDefaults.standard.string(forKey: "state"),
let fileContent = try? String(contentsOfFile: state),
let fileData = fileContent.data(using: .utf8)
else {
return nil
}
return try? JSONDecoder().decode(Models.User.self, from: fileData)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment