Adding a value to the Keychain

- [Instructor] Next, we implement the method…to store a string securely in the keychain.…I'm going to call it set string for key.…Let me make some space here so…that we can see what we're doing.…This method is not private because…it's part of the public API of this facade,…so it's a public method, and I call it,…set, the first parameter is called string, just type string,…the second one is the key, also of type string.…

Now, there may be various issues…while accessing that keychain,…so I make this a throwable method.…First, we validate the input parameters.…I use the guard statement, and first we check…if the string is empty, and then the key, as well.…The guard should fail if any of the input arguments is empty…so I'm going to print an error message to the console,…say, "Can't add an empty string to the keychain."…We should also throw an error,…so let's declare a custom error type.…

I scroll up and define the keychain for said error,…enum, that conforms to the error protocol.…It should be a public enumeration,…

Resume Transcript Auto-Scroll

Author

Released

10/26/2018

Our mobile devices store our most intimate conversations and photos, the payments we make, and an array of other sensitive personal data. App developers that gain access to devices are charged with protecting the security of all that information. In this course, seasoned developer Károly Nyisztor dives into the topic of iOS security, reviewing the means Apple provides to develop secure apps that are safeguarded from current and future threats. Károly goes over fundamental security concepts, including secure boot, sandboxing, and secure networking. He also explains how to secure devices using Touch ID and Face ID, leverage keychain services, perform asymmetric encryption and decryption, and much more.