2017-10-12 35 views
0

我想重现DynamoDB的iOS SDK指南中的示例。我能够查询AWSDynamoDBKeySchemaElements和AWSDynamoDBAttributeDefinitions如下图所示的输出:AWSDynamoDBObjectMapper.load无法从Swift中的表中检索数据

<AWSDynamoDBKeySchemaElement: 0x600000038080> { 
    attributeName = Id; 
    keyType = 1; 
} 

<AWSDynamoDBAttributeDefinition: 0x600000037ec0> { 
    attributeName = Id; 
    attributeType = 2; 
} 

但是,当我尝试使用dynamoDBObjectMapper.load,我的结果让零值。表名是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

现在已经修复。截至目前,AWS不支持Swift 4.0。所以一旦我改变了构建设置以使用Swift 3.2,它就可以正常工作。