matthewpalmer / Locksmith

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

Swift 3 #148

Open alexwibowo opened 7 years ago

alexwibowo commented 7 years ago

Hi,

I have just updated my project to swift 3. I have the following Podfile config for Locksmith:

pod "Locksmith", :git => 'https://github.com/matthewpalmer/Locksmith.git', :branch => 'swift-3.0'

When I tried to open my project, Xcode (8) asked me to convert the project syntax to Swift 3. I did. Now I'm getting the following error on Locksmith:

public extension CreateableSecureStorable where Self : GenericPasswordSecureStorable {
   func createInSecureStore() throws {
        try performSecureStorageAction(performCreateRequestClosure, secureStoragePropertyDictionary: asCreateableSecureStoragePropertyDictionary)
    }
    func updateInSecureStore() throws {
        try self.updateInSecureStore(query: self.asCreateableSecureStoragePropertyDictionary)
    }
}

(line 547 of Locksmith.swift if that helps)

Xcode complains about self.updateInSecureStore(), saying 'Argument passed to call that takes no arguments'. The same error also occurred on

public extension CreateableSecureStorable where Self : InternetPasswordSecureStorable {
    func createInSecureStore() throws {
        try performSecureStorageAction(performCreateRequestClosure, secureStoragePropertyDictionary: asCreateableSecureStoragePropertyDictionary)
    }
    func updateInSecureStore() throws {
        try self.updateInSecureStore(query: self.asCreateableSecureStoragePropertyDictionary)
    }
}

(line 572 of Locksmith.swift if that helps)

Have I done something wrong on my Podfile branch config?

Thanks in advance for the help & the awesome library!

matthewpalmer commented 7 years ago

There's a release version of Locksmith (3.0.0)—try it out and reopen if the issue persists 👍

alexwibowo commented 7 years ago

Hi,

THanks for the prompt response! I have tried master (Locksmith 3.0.0), but the issue still persists. I would have tried to fix it myself, but I'm not familiar with Swift 3 syntax. I can see the following definition - so I dont know why xcode is complaining about it:


extension CreateableSecureStorable {
    func updateInSecureStore(_ query: [String: Any]) throws {
        var attributesToUpdate = query
        attributesToUpdate[String(kSecClass)] = nil

        let status = SecItemUpdate(query as CFDictionary, attributesToUpdate as CFDictionary)

        if let error = LocksmithError(fromStatusCode: Int(status)) {
            if error == .notFound || error == .notAvailable {
                try self.createInSecureStore()
            } else {
                throw error
            }
        } else {
            if status != errSecSuccess {
                throw LocksmithError.undefined
            }
        }
    }
}
matthewpalmer commented 7 years ago

Would you be able to create a sample project replicating this issue? Thanks!

alexwibowo commented 7 years ago

Actually. I played around with the compile error, and figured out what was wrong. Then I went to GitHub to look at the latest code, and it seems that your code was doing the same thing that I did ! So... it seems that Xcode 8 has broken the code while trying to fix my project into swift 3 syntax.  Basically it puts underscore as external parameter on that function. Your original code did not specify external parameter name. Don't know why Xcode thinks that it should be fixed that way ! Best regards Alex

Get Outlook for iOS

On Sat, Sep 17, 2016 at 6:17 PM +1000, "Matthew Palmer" notifications@github.com wrote:

Would you be able to create a sample project replicating this issue? Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

thewhitewood commented 7 years ago

Same issue for me - do we know of a fix?

alexwibowo commented 7 years ago

Hi Nick, For me it is broken because Xcode is trying to be smart by fixing the function parameter.Just remove the external parameter name, and you should be ready to rock and roll again. I know it is a little hassle - as you probably would need to update the file every time you do pod install, but it is a short term fix :). Hope that helps ! Best regards Alex Get Outlook for iOS

On Tue, Sep 20, 2016 at 2:43 AM +1000, "Nick Wood" notifications@github.com wrote:

Same issue for me - do we know of a fix?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

benmann497 commented 7 years ago

Hi, i was just wondering if there's a fix for this? I am using the latest 3.0.0 Master pod release and XCode 8 is still determined that it needs to be converted to Swift 3 (or 2.3). On allowing this to happen i get 50 build errors.

I tried forcing to use the Swift 3 older branch, which worked, until build time where the Linker failed saying it was build with Swift 2!

GhostBob commented 7 years ago

I fixed mine by setting 'Use Legacy Swift Language Version' to No on the Pods project and doing a clean of the build folder and the project. Not sure if all those steps were necessary. But until it breaks again...why poke the bear?

benmann497 commented 7 years ago

Thanks GhostBob, that worked a treat.

oney commented 7 years ago

If you ever converted codes of Locksmith to Swift 3, change back to original codes.

In Locksmith.swift, change

extension CreateableSecureStorable {
    func updateInSecureStore(_ query: [String: Any]) throws {

to

extension CreateableSecureStorable {
    func updateInSecureStore(query: [String: Any]) throws {