1

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.

1
  • String should work for the model type. I have a Swift 4 project and it is working fine for me. To help me debug better, could you confirm if these are the only two attributes in the table? Do operations like get / insert/ query work correctly? Is scan with filter only impacted? What is the SDK version you are using? Commented Oct 7, 2017 at 4:03

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.