matthewpalmer / Locksmith

A powerful, protocol-oriented library for working with the keychain in Swift.
MIT License
2.92k stars 268 forks source link

Swift 4 - multiple-argument function types causing Parameter Error #181

Closed phillfarrugia closed 6 years ago

phillfarrugia commented 6 years ago

Even though the project compiles within Swift 4, I suspect that there are some underlying issues causing unexpected behavior when writing/reading from the keychain.

In a project that uses Locksmith, calling try Locksmith.saveData(data:forUserAccount:inService:) is throwing a param error.

From my investigations into why this might be occurring the source of the error is in Locksmith.swift line 559-565. I suspect it may be being caused by the use of $0 to pass a closure parameter value into another closure. If I understand correctly Swift 4.0 does introduce some changes to this syntax?

public extension CreateableSecureStorable {
    var performCreateRequestClosure: PerformRequestClosureType {
        return { (requestReference: CFDictionary, result: inout AnyObject?) in
            return withUnsafeMutablePointer(to: &result) { SecItemAdd(requestReference, UnsafeMutablePointer($0)) }
        }
    }
}

Thanks

phillfarrugia commented 6 years ago

@matthewpalmer Ah! A colleague of mine investigated further and we've discovered this is the cause of the issue I was experiencing, not actually Locksmith itself.

For reference, Xcode 9 requires Unit Tests to be connected to an App Target as Host in order to access the keychain https://stackoverflow.com/questions/46299406/reading-from-keychain-xcode-9-simulators-returns-nothing