2017-05-16 39 views
1

在此先感謝您的幫助。我正在嘗試使用AWS iOS SDK(Swift)從一個DynamoDb表中獲取批項目(加載多個)項目。我可以使用塊語法加載一個項目,但我需要加載10或更多。我不想使用10個塊調用來單獨加載它們。我試圖按照附加stackoverflow鏈接(類似的解決方案給出),但我收到以下編譯器錯誤消息。我來自Java背景,因此也可能是一個語法問題。這是加載多個項目的正確方法嗎?我不想使用低級別的API。任何幫助,我哪裏出錯了。謝謝。aws dynamodb如何使用批量獲取ios swift的對象映射器

AnyObject? is not convertible to Any?

aws dynamodb how to use object mapper with batch get in ios

let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default() 
     var tasksList = Array<AWSTask<AnyObject>>() 
     for i in 1...10 { 

      tasksList.append(dynamoDBObjectMapper.load(AWSCards.self, hashKey: "SH_"+String(i), rangeKey: nil)) 
     } 

     AWSTask.init(forCompletionOfAllTasksWithResults: tasksList).continueWithBlock { (task) -> AnyObject? in 
         if let cards = task.result as? [AWSCards] { 
          print(cards.count) 
         } 
         else if let error = task.error { 
          print(error.localizedDescription) 
         } 
         return nil 
       } 

回答

0

有以下代碼一試(雨燕4.1,2018年2月9日):

let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default() 
     var tasksList = Array<AWSTask<AnyObject>>() 
     for i in 1...10 { 

      tasksList.append(dynamoDBObjectMapper.load(AWSCards.self, hashKey: "SH_"+String(i), rangeKey: nil)) 
     } 

     AWSTask<AnyObject>.init(forCompletionOfAllTasksWithResults: tasksList).continueWith { (task) -> Any? in 
         if let cards = task.result as? [AWSCards] { 
          print(cards.count) 
         } 
         else if let error = task.error { 
          print(error.localizedDescription) 
         } 
         return nil 
       } 
相關問題