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.

Removing items from the Keychain

Removing items from the Keychain - iOS Tutorial

From the course: iOS Development: Security

Start my 1-month free trial

Removing items from the Keychain

- [Instructor] We can avoid the duplicate item error upon adding an item to the key chain by removing it if it already exists. So, let's add a new method through the key chain facade class. I'm going to switch to our key chain facade file. Let's make some place here and let's add a new method called remove string. I'm going to make it public too. The method has a single argument of type string. This is the unique identifier of the item we want to delete from the key chain. I mark the method as throw able since removing an item from the key chain might fail for various reasons. Let me scroll up a bit. Next, we'll validate the key. I'm going to use the guard statement. The key shouldn't be empty. As I print a warning message and throw a key chain facade error. The message is key must be valid and I throw an error of type invalid content. If everything goes well and our key is valid we can use the set item delete function to delete the item. This function takes a query dictionary with…

Contents