From the course: Advanced iOS Development: Keychain Access

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Storing a generic password

Storing a generic password - iOS Tutorial

From the course: Advanced iOS Development: Keychain Access

Start my 1-month free trial

Storing a generic password

- [Instructor] So, we have our data, now we just need to store it in the dictionary. So, I'm going to write that as a separate function so we can reuse it as necessary. So, after line nine inside of our SecureMgr class I'm going to create a few blank lines and start my new function on line 11. So, I'll say static func addToKeychain, and it's going to have one parameter of query, it's the same type as our dictionary before, so it'll be String, key type, and Any as the value type and it's going to return a Bool. So, we'll be able to call this from our store log in and return its result directly. So, on line 12, I'm going to store it in the Keychain and I'm going to say let result, we'll store the result in that constant, and I'll call SecItemAdd and I'll pass in the query and cast it as a CFDictionary. Now, the second parameter will store the result Keychain item in it, and if you want to be able to inspect that, you can.…

Contents