vandadnp / iOS-8-Swift-Programming-Cookbook

This is the GitHub repository of O'Reilly's iOS 8 Swift Programming Cookbook
1.35k stars 481 forks source link

Reading values from Keychain does not work when in Release mode #5

Open moshegutman opened 9 years ago

moshegutman commented 9 years ago

I'm unable to read values from the Keychain when using the Swift compiler Optimization Level [Fastest -O], which is default for Release mode apps.

https://github.com/vandadnp/iOS-8-Swift-Programming-Cookbook/blob/master/chapter-security/Finding%20Values%20in%20the%20Keychain/Finding%20Values%20in%20the%20Keychain/AppDelegate.swift

Seems like these lines are the problem:

var returnedData: Unmanaged<AnyObject>? = nil
let results = Int(SecItemCopyMatching(query, &returnedData))

Possible solution: http://stackoverflow.com/questions/24145838/querying-ios-keychain-using-swift

var returnedData: AnyObject?
var results = withUnsafeMutablePointer(&returnedData) { SecItemCopyMatching(query, UnsafeMutablePointer($0)) }
vandadnp commented 9 years ago

Hi there, what is the value in the results variable after you call the SecItemCopyMatching() function? Thanks.

moshegutman commented 9 years ago

It is an OSStatus object. Upon success its value will be equal to errSecSuccess