ios - aws dynamodb 如何在 ios swift 中使用对象映射器和批处理获取

标签 ios swift amazon-web-services amazon-dynamodb aws-sdk

在此先感谢您的帮助。我正在尝试使用 AWS iOS SDK (Swift) 从一个 DynamoDb 表中获取批处理项目(加载多个)项目。我可以使用 Block 语法加载一项,但我需要加载 10 项或更多项。我不想使用 10 个 Block 调用来单独加载它们。我试图遵循附加的 stackoverflow 链接(其中给出了类似的解决方案),但我收到以下编译器错误消息。我来自 Java 背景,因此也可能是语法问题。这是加载多个项目的正确方法吗?我不想使用低级 API。任何帮助,我哪里出错了。谢谢。

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
 }

最佳答案

尝试使用以下代码(Swift 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
                }

关于ios - aws dynamodb 如何在 ios swift 中使用对象映射器和批处理获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44004055/

相关文章:

ios - 使用 ionic 输入时,Ionic 2页面在iOS中上下跳跃

ios - 在 iPad 上创建弹出 ListView

node.js - 无服务器 NodeJS/ native node_modules

node.js - 将 NodeJS 运行时从 8.10 更新到 10.x 或 12.x - AWS Amplify

.net - AWS非Web应用程序部署

iOS - AVPlayer 不播放 mov 文件

ios 设置 UISlider 的起始位置和增量

swift - 使用 Swift 的 SceneKit 中视频纹理对象的布局坐标

swift - 如何在 swift 中更改子类中的属性值?

Swift 1.2 连接字符串