简体   繁体   English

执行放置项目请求-AWS DynamoDB ios SDK

[英]execute put item request - AWS DynamoDB ios SDK

Looked all over SO and through Amazon's docs as well, but couldn't find any solid documentation on how to make a put request using iOS SDK, specifically using Swift. 在整个SO中以及亚马逊的文档中进行了全面查看,但是找不到有关如何使用iOS SDK(特别是使用Swift)发出放置请求的可靠文档。

I gather that I need to instantiate an AWSDynamoDBClient first ( https://aws.amazon.com/articles/7439603059327617 ) but don't see that appear as a type when I'm working in xcode. 我收集到我需要首先实例化一个AWSDynamoDBClient( https://aws.amazon.com/articles/7439603059327617 ),但是当我在xcode中工作时看不到它是一种类型。

I've honestly only got two lines of code after all this struggle: 坦白地说,经过所有这些努力,我只有两行代码:

var myDynamoDBPutRequest:AWSDynamoDBPutRequest = AWSDynamoDBPutRequest()
    myDynamoDBPutRequest.item = ["fbid": "test"]

I can't figure out how to run it, and doubt that request is set up properly anyway. 我不知道如何运行它,并且怀疑该请求是否正确设置。 I've also looked at PutItemInputs, but not sure how that differs from putRequest.item. 我也看过PutItemInputs,但不确定与putRequest.item有何不同。 If anyone can just point me in the right direction I'll be happy to investigate on my own - I'm just running out of places to look for good documentation :/ 如果有人可以指出正确的方向,我将很乐意独自进行调查-我用光了地方来寻找好的文档:/

EDIT: 编辑:

I've made a bit of progress, but still can't figure out how to properly create a put item input . 我已经取得了一些进展,但是仍然不知道如何正确创建放置项输入。 Here is the code I have now: 这是我现在拥有的代码:

 var myPutItemInput:AWSDynamoDBPutItemInput = AWSDynamoDBPutItemInput()
    myPutItemInput.tableName = "mytable"

    var myDynamoDB = AWSDynamoDB.defaultDynamoDB()

    myDynamoDB.putItem(myPutItemInput).continueWithBlock { (task:BFTask!) -> AnyObject! in
        if(task.result != nil){
            let myPutOutput = task.result as AWSDynamoDBPutItemOutput

            println(task.result)

        }else{
            println("task.result was nil for put item request")
        }

        return nil
    }//end put item task

right now I at least figured out how to execute the request, but the result is nil each time. 现在,我至少想出了如何执行请求,但是每次都没有结果。

Here is an example of - putItem : 这是- putItem的示例:

let dynamoDB = AWSDynamoDB.defaultDynamoDB()

let putItemInput = AWSDynamoDBPutItemInput()
putItemInput.tableName = "testTableName"
let hashValue = AWSDynamoDBAttributeValue()
hashValue.S = "testPutItem"
let stringValue = AWSDynamoDBAttributeValue()
stringValue.S = "stringValue";
putItemInput.item = [
    "hashKey" : hashValue,
    "stringKey" : stringValue
]

dynamoDB.putItem(putItemInput).continueWithBlock { (task:AWSTask?) -> AnyObject? in
    if(task.error != nil) {
        println(task.error)
    }

    if (task.result != nil) {
        let putItemOutput = task.result as AWSDynamoDBPutItemOutput
        println(putItemOutput)
    }

    return nil
}

Even though it's in Objective-C, looking at the integration tests may help understand how to use Amazon DynamoDB with the AWS Mobile SDK for iOS v2. 即使在Objective-C中,查看集成测试也可能有助于了解如何将Amazon DynamoDB与适用于iOS v2的AWS Mobile SDK结合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM