AWS APIGatewayClient(Swift) doesn't work in Swift3?

539 Views Asked by At

Following README.md, I've set the bridging header including AWSApiGatewayBridge.h.

The generated client SDK written by Swift has a lot of compiler errors in Swift 3 so I've replaced the generated Swift 2 code with Swift 3.

I replaced them all:Not instanciate an Object from APIGatewayClient class.

But Xcode says a following error message.

"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1"

The generated Client.swift has init function.

init(configuration: AWSServiceConfiguration) {
    super.init()
    self.configuration = configuration.copy() as! AWSServiceConfiguration
    ...
}

In the function, I found a line making the error. But I couldn't find the way to fix it.

self.configuration = configuration.copy() as! AWSServiceConfiguration

If the line was commented out, Xcode can compile successfully.

Is the error caused by Xcode setting or my personal problem? Anyone can use APIGatewayClient(Swift) in Swift 3?

i use Xcode ver8.2.1

2

There are 2 best solutions below

0
On

The generated client Swift SDK does not work in Swift 3.

You need to use the Objective C generated SDK if your application is written by Swift 3.

https://github.com/aws/aws-sdk-ios/issues/510

1
On

I had a similar issue with the AWSServiceConfiguration when i upgraded to Xcode Version 8.2.1 (8C1002). It would give me the same error on the assignment of the assignment you mention self.configuration = configuration.copy() as! AWSServiceConfiguration.

I override the AWSServiceConfiguration in my AWSAPIGatewayClient subclass and used a local var as a go between. Then use that in the assignment

Below is my work around. Hope it helps.

var customConfig:AWSServiceConfiguration?

override open var configuration: AWSServiceConfiguration{
    get {
            guard let config = customConfig else{
                return AWSServiceConfiguration()
            }
        return config
    }
    set(value) {
        self.customConfig = value
    }
}

Then do the assignment like this.

init(configuration: AWSServiceConfiguration) {
    super.init()

    //the below asignment causes a linking error
    // self.configuration = configuration.copy() as! AWSServiceConfiguration

    //this is the new assignment
    self.customConfig  = configuration.copy() as? AWSServiceConfiguration

    var URLString: String = "https://xxxxx.execute-api.us-east-1.amazonaws.com/xxxx"
    if URLString.hasSuffix("/") {
        URLString = URLString.substring(to: URLString.characters.index(URLString.startIndex, offsetBy: URLString.lengthOfBytes(using: String.Encoding.utf8) - 1))
    }

    self.configuration.endpoint = AWSEndpoint(region: self.configuration.regionType, service: .apiGateway, url: URL(string: URLString)!)

    let signer: AWSSignatureV4Signer = AWSSignatureV4Signer(credentialsProvider: self.configuration.credentialsProvider, endpoint: self.configuration.endpoint)

    if let endpoint = self.configuration.endpoint {
        self.configuration.baseURL = endpoint.url
    }
    self.configuration.requestInterceptors = [AWSNetworkingRequestInterceptor(), signer]
}