2017-10-12 40 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,它就可以正常工作。