Skip to content

Instantly share code, notes, and snippets.

@paulw11
Last active January 23, 2022 19:08
Show Gist options
  • Save paulw11/7772e98743bcf39407e2bad884018330 to your computer and use it in GitHub Desktop.
Save paulw11/7772e98743bcf39407e2bad884018330 to your computer and use it in GitHub Desktop.
import Passbase
class MyPassbaseWrapper {
static func initialisePassbase:(_ apiKey: String) {
PassbaseSDK.initialize(publishableApiKey: apiKey)
}
}
@dbarrett
Copy link

Thanks for helping me... I'm primarily an ObjC guy... I'm lacking in my understanding of Swift, unfortunately... learning though.
I'm working with this code you provided and I got a few errors. I made the suggested changes to this:

import Passbase

class MyPassbaseWrapper {

    static func initialisePassbase() -> (String) {
        PassbaseSDK.initialize(publishableApiKey: apiKey)
   }
}

Getting this error for "apiKey"... Swift Compiler Error: Cannot find 'apiKey' in scope
Unsure how to proceed.

@paulw11
Copy link
Author

paulw11 commented Jan 22, 2022

That’s not correct. My first code was correct. apiKey is the parameter passed to the function. You could add a -> Void return type to the function, but it doesn’t return a string.

@paulw11
Copy link
Author

paulw11 commented Jan 22, 2022

You might also need to add the @objc decorator to the function.

@dbarrett
Copy link

ok... will try. Thank you!

@dbarrett
Copy link

dbarrett commented Jan 23, 2022

These are the errors I get without making any changes to your code:

::ERROR:: swiftWrapper.swift:14:40: Expected '(' in argument list of function declaration
Current code: @objc static func initialisePassbase:(_ apiKey: String)
Xcode suggested change(fix): @objc static func initialisePassbase():(_ apiKey: String)
::ERROR:: swiftWrapper.swift:14:40: Expected '->' after function parameter tuple
Current code: @objc static func initialisePassbase:(_ apiKey: String)
Xcode suggested change(fix): @objc static func initialisePassbase -> (_ apiKey: String)
::ERROR:: swiftWrapper.swift:14:42: Tuple element cannot have two labels
Current code: @objc static func initialisePassbase:(_ apiKey: String)
Xcode suggested change(fix): @objc static func initialisePassbase:(String)
::ERROR:: swiftWrapper.swift:15:51: Cannot find 'apiKey' in scope
Current code: PassbaseSDK.initialize(publishableApiKey: apiKey)
Xcode suggested change(fix): NONE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment