Ios 从DynamoDB中的表中获取信息

Ios 从DynamoDB中的表中获取信息,ios,swift,amazon-web-services,amazon-dynamodb,Ios,Swift,Amazon Web Services,Amazon Dynamodb,我正试图找到在DynamoDB中查询(扫描)表的方法。 这是我的代码,几乎可以工作了 let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default(), scanExpression = AWSDynamoDBScanExpression() dynamoDbObjectMapper.scan(MyTable.self, expression: scanExpression) { (output: A

我正试图找到在
DynamoDB
中查询(扫描)表的方法。 这是我的代码,几乎可以工作了

    let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default(),
    scanExpression = AWSDynamoDBScanExpression()
    dynamoDbObjectMapper.scan(MyTable.self, expression: scanExpression) {
        (output: AWSDynamoDBPaginatedOutput?, error: Error?) in
        if error != nil {
            print("The request failed. Error: \(String(describing: error))")
        }

        if output != nil {
            print("Item count: \(output!.items.count)")
            for item in output!.items {
                let theItem = item as? MyTable
                print("theItem: \(theItem!._vcIdKey!)")
            }
        }
    }
当我运行此代码时,我可以看到列出的一项,而实际上表中有七项

事实上,我想要一个项目,但我想我需要为此添加这一行(我不必):

为什么会这样?

第二个问题是我得到最后一个元素,我想得到第一个

我需要更改什么?

更多信息:我还尝试了以下代码,得到了非常相同的结果

    dynamoDbObjectMapper.scan(VoChaAudioPost.self, 
                              expression: scanExpression).continueWith(block: {
        (task:AWSTask<AWSDynamoDBPaginatedOutput>!) -> Any? in

        if let error = task.error as NSError? {
            print("The request failed. Error: \(error)")
        } else if let output = task.result {
            print("items count: \(output.items.count)")
            for item in output.items /*as! VoChaAudioPost*/ {
                // Do something with item.
                print("item : \(item)")
            }
        }
        return()
    })
dynamodbobbjectmapper.scan(VoChaAudioPost.self,
表达式:scanExpression)。继续(块:{
(任务:AWSTask!)->有吗
如果let error=task.error作为NSError{
打印(“请求失败。错误:\(错误)”)
}如果让输出=task.result,则为else{
打印(“项目计数:\(output.items.count)”)
对于output.items/*as!VoChaAudioPost*/{
//对这个项目做些什么。
打印(“项目:\(项目)”)
}
}
返回()
})

你能按照这个例子进行比较吗?我想看看,但是如果我使用它,我会得到一个错误:不能用类型为“(block:(AWSTask!)->Any?)的参数列表调用“continueWith”(continueWith),我该怎么办?我将:“(task:AWSTask!)->Any in”改为:“(task:AWSTask!)->Any in”,并且它可以工作(至少我消除了这个错误).然后当我运行时,我得到这个:[11291:4791952]任务。已完成,但出现错误-代码:-1001[11291:4791956]TIC TCP连接失败[1:0x155ecbb70]:1:50错误(50)[11291:4791956]任务。HTTP加载失败(错误代码:-1009[1:50])。。。。书:{“uxxidkey”=“9A03387F-B76C-4495-AB22-FC8DAB9SS981”;“uyyidkey”=XYZ15248266777222119891;}第一项之后似乎有什么东西崩溃了。这就解释了为什么我没有得到一个以上的项目。
    dynamoDbObjectMapper.scan(VoChaAudioPost.self, 
                              expression: scanExpression).continueWith(block: {
        (task:AWSTask<AWSDynamoDBPaginatedOutput>!) -> Any? in

        if let error = task.error as NSError? {
            print("The request failed. Error: \(error)")
        } else if let output = task.result {
            print("items count: \(output.items.count)")
            for item in output.items /*as! VoChaAudioPost*/ {
                // Do something with item.
                print("item : \(item)")
            }
        }
        return()
    })