Front-End Web & Mobile
AWS Mobile SDK for iOS version 2.5.0 – Improvements and changes to Swift support
What
Version 2.5.0 of the AWS Mobile SDK for iOS introduces better compatibility for a Swift 3 migration.
This blog walks through improvements and breaking changes with this SDK release that are relevant for Swift developers.
When you open your legacy Swift 2.x project with Xcode 8.0 for the first time, you will be prompted by the Swift Migration Assistant to migrate to Swift 3. The following changes have been made to the AWS Mobile SDK for iOS to better support the migration.
Compatibility Improvements
AWS Mobile SDK for iOS version 2.5.0 now has better support for Auto-Completion, added generics, and improved name translation for AWSTask so that it handles the Xcode 8 Swift Migration Assistant gracefully and predictably.
Here are some examples of the changes that will improve the migration to Swift 3:
- Added more generics support for public APIs. For example, in Amazon Cognito Sync, dataset.getAllRecords() now returns an array of type AWSCognitoRecord instead of an array without a type.
- Improved name translation for AWSTask continueWithSuccessBlock and continueWithBlock. This enables Xcode to distinguish these methods and it avoids returning an ambiguous use of the continue error message. To illustrate, The following is an asynchronous call to list Amazon DynamoDB tables:
Prior to iOS SDK 2.5.0
let dynamoDB = AWSDynamoDB.defaultDynamoDB()
let listTableInput = AWSDynamoDBListTablesInput()
dynamoDB.listTables(listTableInput).continueWithBlock{ (task: AWSTask?) -> AnyObject? in
if let error = task.error {
print("Error occurred: \(error)")
return nil
}
let listTablesOutput = task.result as AWSDynamoDBListTablesOutput
for tableName in listTablesOutput.tableNames {
print("\(tableName)")
}
return nil
}
After iOS SDK 2.5.0
let dynamoDB = AWSDynamoDB.default()
let listTableInput = AWSDynamoDBListTablesInput()
dynamoDB.listTables(listTableInput!).continueWith{ (task:AWSTask<AWSDynamoDBListTablesOutput>) -> Any? in
if let error = task.error as? NSError {
print("Error occurred: \(error)")
return nil
}
let listTablesOutput = task.result
for tableName in listTablesOutput!.tableNames! {
print("\(tableName)")
}
return nil
}
- When migrating legacy Swift code to iOS SDK 2.5.0, continue to use Swift 2.3 syntax for AWS region and service naming conventions. For example: use .USEast1 instead of .usEast1, and use SNS instead of sNS. We made the decision to go against standard Swift 3 naming practices to provide consistency across all AWS region values and service enums.
Swift 3 sample code has been updated and added where appropriate in our AWS Mobile SDK for iOS Samples GitHub repository, in our API reference documentation, and in the AWS Mobile SDK for iOS Developer Guide. Support for a Swift 3 sample app on AWS Mobile Hub is coming soon.
Questions or Comments?
Raise an issue on GitHub or reach out to us via the AWS Mobile Development Forum.