我正在尝试重现DynamoDB的iOS SDK指南中的示例。我可以查询AWSDynamoDBKeySchemaElements和AWSDynamoDBAttributeDefinitions,如下面的输出所示:
<AWSDynamoDBKeySchemaElement: 0x600000038080> {
attributeName = Id;
keyType = 1;
}
<AWSDynamoDBAttributeDefinition: 0x600000037ec0> {
attributeName = Id;
attributeType = 2;
}
但是当我尝试使用dynamoDBObjectMapper.load时,我在结果中得到了nil值。表名是ProductCatalog,类定义是:
import Foundation
import AWSDynamoDB
class ProductCatalog: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
var Id: NSNumber?
var PageCount: NSNumber?
var Title: String?
class func dynamoDBTableName() -> String {
return "ProductCatalog"
}
class func hashKeyAttribute() -> String {
return "Id"
}
}
我使用的查询是:
dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default()
dynamoDBObjectMapper.load(ProductCatalog.self, hashKey: 101, rangeKey: nil).continueWith(block:
{(task: AWSTask<AnyObject>) -> Any? in
if let error = task.error as NSError? {
print ("The request failed with \(error)")
} else if let resultBook = task.result as? ProductCatalog {
print("Title:", resultBook.Title)
}
return nil
})
表格中包含Id为101的行:
{
"Authors": [
"Author1"
],
"Dimensions": "8.5 x 11.0 x 0.5",
"Id": 101,
"InPublication": true,
"ISBN": "111-1111111111",
"PageCount": 500,
"Price": 2,
"ProductCategory": "Book",
"Title": "Winterdance"
}
我这两天一直在努力奋斗。任何帮助将不胜感激。
答案 0 :(得分:0)
现在已经修好了。 AWS目前不支持Swift 4.0。因此,一旦我将构建设置更改为使用Swift 3.2,它就可以正常工作。