From the course: iOS Development: Security
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Adding a value to the Keychain - iOS Tutorial
From the course: iOS Development: Security
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…
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
-
-
-
-
-