From the course: iOS Development: Security
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Restore values from the Keychain - iOS Tutorial
From the course: iOS Development: Security
Restore values from the Keychain
- [Instructor] Now let's use this new feature in the ViewController. Let me switch to the ViewController. In the viewDidLoad method I retrieve the strings we persisted in the Keychain. So let's crawl down to the viewDidLoad method. And I'm going to add the required code. I use the guard statement to check if the string forKey method calls were successful. Guard let username equals I'm going to use try question mark which ignores if an error was thrown and return is nil. Try keychain .string forKey. And the key for the username was username as we can see here. So let's copy and paste it from that part. And also let's fetch the password equals try question mark keychain.string forKey and I'll be using the key for the password. If any of these calls fails I print a warning message and return. Print. Could not retrieve credentials from Keychain. And let's return. Now if the call succeeds we set the username and the password for the corresponding task fields. Let' scroll up a bit so we can…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Keychain overview1m
-
(Locked)
Implementing a Keychain wrapper3m 3s
-
(Locked)
Adding a value to the Keychain5m 9s
-
(Locked)
Using the Keychain wrapper4m 31s
-
(Locked)
Removing items from the Keychain3m 30s
-
(Locked)
Retrieve items from the Keychain4m 33s
-
(Locked)
Restore values from the Keychain2m 19s
-
-
-
-
-