AWS Dynamo DB对象映射器错误

时间:2015-10-15 20:32:30

标签: swift amazon-web-services amazon-dynamodb aws-sdk

我正在尝试通过swift代码查询我的AWS Dynamo数据库表“UserCreds”。我首先定义了一个类,然后将其映射到Dynamo DB表。然后我调用AWSDynamoDBQueryExpression()来搜索该表上的一行。 但程序不断崩溃,出现以下错误:

“ViewController11viewDidLoadFS0_FT_T_L_11DDBTableRow dynamoDBTableName]:无法识别的选择器发送到类0x102ec3d40]”

我还确保在AppDelegate文件中设置了正确的凭据。任何洞察原因可能会失败的原因将非常感激。谢谢!

下面是代码:

导入UIKit

类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
    })

}

1 个答案:

答案 0 :(得分:0)

在ViewController类中的viewDidLoad()方法中使用DDBTableRow类定义是否明智?