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.

Keychain search query

Keychain search query - iOS Tutorial

From the course: Advanced iOS Development: Keychain Access

Start my 1-month free trial

Keychain search query

- [Instructor] Now let's look at how we can use this SecItemCopyMatching in our code to fetch an item out of a keychain. So back in Xcode, I'm going to create a new function up here at the top. So after the class declaration on line nine, I'll create some empty lines and a new function on line 11. I'll make it static func retrievePassword. And we only have to pass in the username. So I'll pass in username as a string and we're going to return a string optional because we may not find a password. And then the next thing I'm going to do is create my query specifying how I want to find this. It's very similar to how we added it, so I'm actually going to copy lines 38 through 41, the query from our original store login function, and I'm going to paste that on line 12. So now I've got this query, but we're not passing in the password anymore. So I'll delete this line where we pass in the password data. I'm just going to pass…

Contents