Reputation: 626
I recently updated my project to Swift 4, and now when I scan my Amazon database the attributes return nil. Here is my scanning code:
let scanExpression = AWSDynamoDBScanExpression()
scanExpression.filterExpression = "contains(Name, :name)"
scanExpression.expressionAttributeValues = [":name": (user?.username)!]
dynamoDBObjectMapper.scan(DBPerson.self, expression: scanExpression).continueWith(block: { (task:AWSTask!) -> Any? in
if let error = task.error as NSError? {
print("The request failed. Error: \(error)")
} else if let paginatedOutput = task.result {
DispatchQueue.main.async(execute: {
self.people.removeAll()
for person in paginatedOutput.items as! [DBPerson] {
self.people += [person] //breakpoint here
}
self.tableView.reloadData()
})
}
return nil
})
And my DBPerson class:
import AWSDynamoDB
class DBPerson : AWSDynamoDBObjectModel, AWSDynamoDBModeling {
var Name: String?
var Occupation: String?
class func dynamoDBTableName() -> String {
return "People"
}
class func hashKeyAttribute() -> String {
return "Name"
}
}
I set a breakpoint inside the scanning loop to look at my attributes, and they always come back as nil. My project was working before the update to Swift 4, showing the attributes in my table. I've tried changing the types of Name and Occupation (in DBPerson class) to things like NSString, NSArray, and even shots in the dark like Substring and CFString.
My DynamoDB table exists with values in them, and the correct number of items return, but the attribute values are always nil. Here is a sample item from my table:
{
"Name": "Bill",
"Occupation": "Firefighter"
}
Is there any solution other than converting back to Swift 3? Thanks.
Upvotes: 1
Views: 522
Reputation: 847
This is due to a change in Swift 4 behavior change of inferencing @objc
. You need to mark the properties available to ObjectiveC by using @objc or mark all properties of class available to ObjectiveC using @objcMembers
For an example refer: https://github.com/aws/aws-sdk-ios/issues/750#issuecomment-337046816
Upvotes: 2