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.

Using the Keychain wrapper

Using the Keychain wrapper - iOS Tutorial

From the course: iOS Development: Security

Start my 1-month free trial

Using the Keychain wrapper

- [Instructor] We have now have a keychain wrapper class that can be used to securely store a string in the keychain. So let's use it. I switch back to our view controller file and I define a lazy variable called keychain. Keychain... and I initialize it using the keychain facade initializer. Next we refactor the unsafe credentials method that uses the insecure user default to store the username and the password. So let's get rid of this code first. Instead, we're going to use the keychain set string for key to persist the username and the password in the keychain. Since this method throws, we need to call it using try from within a do catch block. First, let's add the username. I need to call the method using try and keychain dot set. The string should be the username for key user name. And now let's also set the password. Also here, we use try, keychain dot set, the string should be the password for key password. We need to handle the errors that might be thrown. First, I'll handle…

Contents