I am trying to query my AWS Dynamo DB table "UserCreds" via swift code. I have first defined a class and then mapped it to Dynamo DB table. Then I am calling AWSDynamoDBQueryExpression() to search for a row on this table. but the program keeps crashing with following error:
"ViewController11viewDidLoadFS0_FT_T_L_11DDBTableRow dynamoDBTableName]: unrecognized selector sent to class 0x102ec3d40]"
I have also ensured that I have correct credentials setup in the AppDelegate file. Any insight into the reasons why this could be failing would be much appreciated. Thanks!
Below is what the code looks like:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
class DDBTableRow :AWSDynamoDBObjectModel {
var UserIdentifier:String?
var UserFullName:String?
class func dynamoDBTableName() -> String! {
return "UserCreds"
}
class func hashKeyAttribute() -> String! {
return "UserIdentifier"
}
class func rangeKeyAttribute() -> String! {
return "UserFullName"
}
//MARK: NSObjectProtocol hack
override func isEqual(object: AnyObject?) -> Bool {
return super.isEqual(object)
}
override func `self`() -> Self {
return self
}
}
//SEARCH FOR A ROW
let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
let queryExpression = AWSDynamoDBQueryExpression()
queryExpression.indexName = "UserIdentifier-UserFullName-index"
queryExpression.hashKeyAttribute = "UserIdentifier"
queryExpression.hashKeyValues = "1234"
queryExpression.scanIndexForward = true
dynamoDBObjectMapper.query(DDBTableRow.self, expression: queryExpression).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task:AWSTask!) -> AnyObject! in
if (task.error != nil) {
print("Error: \(task.error)")
let alertController = UIAlertController(title: "Failed to query a test table.", message: task.error.description, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: { (action:UIAlertAction) -> Void in
})
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)
} else {
if (task.result != nil) {
print(task.result)
}
print("Performing Segue")
}
return nil
})
}