Locksmith icon indicating copy to clipboard operation
Locksmith copied to clipboard

Swift 3

Open alexwibowo opened this issue 9 years ago • 10 comments

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!

alexwibowo avatar Sep 17 '16 01:09 alexwibowo

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

matthewpalmer avatar Sep 17 '16 05:09 matthewpalmer

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
            }
        }
    }
}

alexwibowo avatar Sep 17 '16 07:09 alexwibowo

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

matthewpalmer avatar Sep 17 '16 08:09 matthewpalmer

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" [email protected] 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.

alexwibowo avatar Sep 17 '16 10:09 alexwibowo

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

thewhitewood avatar Sep 19 '16 16:09 thewhitewood

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" [email protected] 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.

alexwibowo avatar Sep 19 '16 23:09 alexwibowo

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!

benmann497 avatar Sep 21 '16 10:09 benmann497

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?

GhostBob avatar Sep 21 '16 17:09 GhostBob

Thanks GhostBob, that worked a treat.

benmann497 avatar Sep 22 '16 08:09 benmann497

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 {

oney avatar Sep 25 '16 18:09 oney