DynamoDB加载nil错误

时间:2017-06-15 22:09:31

标签: ios swift

我正在尝试从dynamoBD加载数据并使用标签打印出来。 以下示例:Riot JS Guide 我已经在帐户上创建了一个表格,我可以使用Web浏览器查看其属性。 使用此代码加载数据:

var tableRow: DDBTableRow?
func getTableRow() {
    let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default()

    dynamoDBObjectMapper .load(DDBTableRow.self, hashKey: (tableRow?.PhotoId)!, rangeKey: tableRow?.UserId) .continueWith(executor: AWSExecutor.mainThread(), block: { (task:AWSTask!) -> AnyObject! in
        if let error = task.error as? NSError {
            print("Error: \(error)")
            let alertController = UIAlertController(title: "Failed to get item from table.", message: error.description, preferredStyle: UIAlertControllerStyle.alert)
            let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
            alertController.addAction(okAction)
            self.present(alertController, animated: true, completion: nil)
        } else if let tableRow = task.result as? DDBTableRow {
            self.photoIdLabel.text = tableRow.PhotoId
            self.userIdLabel.text = tableRow.UserId
            self.photoDateLabel.text = tableRow.PhotoDate
            self.photoURLLabel.text = tableRow.PhotoURL
            self.photoCategoryLabel.text = tableRow.PhotoCategory
        }

        return nil
    })
}

在log:tableRows [MyProject.DDBTableRow]中?没有。

示例代码工作正常,我不知道有什么问题。在调用load之前我会错过什么吗?我觉得非常接近解决它。请帮忙!

0 个答案:

没有答案