增加AWS DynamoDB中的Number属性目标C.

时间:2022-06-29 09:06:29

I am struggling with incrementing a number property value of an item already saved in my table on DynamoDB my code currently is:

我正在努力增加我在DynamoDB上保存在表格中的项目的数字属性值,我的代码目前是:

        AWSDynamoDBUpdateItemInput *updateItemInput = [AWSDynamoDBUpdateItemInput new];
        updateItemInput.tableName = @"Table";

        updateItemInput.key= @{
                               @"KeyPropertyName":@"KeyValue"
                                };
        updateItemInput.updateExpression = @"SET(counter = counter + :val)";
        updateItemInput.expressionAttributeValues =@{
                                                     @":val":@1
                                                     };
        AWSDynamoDB *dynamoDB = [AWSDynamoDB defaultDynamoDB];

        [[dynamoDB updateItem:updateItemInput]
         continueWithBlock:^id(AWSTask *task) {
             if (task.error) {
                 NSLog(@"The request failed. Error: [%@]", task.error);
             }
             if (task.exception) {
                 NSLog(@"The request failed. Exception: [%@]", task.exception);
             }
             if (task.result) {
                 //Do something with result.
             }
             return nil;
         }];

My app always crashes when I do not comment out the updateExpression and expressionAttributeValues. I can reach the block when I create an empty instance of my item type and get strange results when I create an instance of AWSDynamoDBAttributeValue to pass in the key. Any suggestions? Am I also improperly writing my updateExpression?

当我没有注释掉updateExpression和expressionAttributeValues时,我的应用程序总是崩溃。当我创建一个我的项类型的空实例时,我可以到达块,当我创建一个AWSDynamoDBAttributeValue实例传入密钥时,会得到奇怪的结果。有什么建议么?我还不正确地写了我的updateExpression吗?

I am also going to be adding updating and deleting items in array/list and dictionary/map properties on another object. How would this differ?

我还将在另一个对象上添加更新和删除数组/列表和字典/地图属性中的项目。这会有什么不同?

1 个解决方案

#1


2  

There are a couple of things. key is defined as follows:

有几件事情。 key的定义如下:

@property (nonatomic, strong) NSDictionary<NSString *, AWSDynamoDBAttributeValue *> * _Nullable key;

You need to replace @"KeyValue" with an instance of AWSDynamoDBAttributeValue.

您需要将@“KeyValue”替换为AWSDynamoDBAttributeValue的实例。

expressionAttributeValues is defined as follows:

expressionAttributeValues定义如下:

@property (nonatomic, strong) NSDictionary<NSString *, AWSDynamoDBAttributeValue *> * _Nullable expressionAttributeValues;

You need to replace @1 with an instance of AWSDynamoDBAttributeValue.

您需要将@ 1替换为AWSDynamoDBAttributeValue的实例。

Make sure to use the latest version of the AWS SDK for iOS so that you can see the generics annotations in the header file. It helps you construct the proper request object.

确保使用最新版本的AWS SDK for iOS,以便您可以在头文件中查看泛型注释。它可以帮助您构建正确的请求对象。

#1


2  

There are a couple of things. key is defined as follows:

有几件事情。 key的定义如下:

@property (nonatomic, strong) NSDictionary<NSString *, AWSDynamoDBAttributeValue *> * _Nullable key;

You need to replace @"KeyValue" with an instance of AWSDynamoDBAttributeValue.

您需要将@“KeyValue”替换为AWSDynamoDBAttributeValue的实例。

expressionAttributeValues is defined as follows:

expressionAttributeValues定义如下:

@property (nonatomic, strong) NSDictionary<NSString *, AWSDynamoDBAttributeValue *> * _Nullable expressionAttributeValues;

You need to replace @1 with an instance of AWSDynamoDBAttributeValue.

您需要将@ 1替换为AWSDynamoDBAttributeValue的实例。

Make sure to use the latest version of the AWS SDK for iOS so that you can see the generics annotations in the header file. It helps you construct the proper request object.

确保使用最新版本的AWS SDK for iOS,以便您可以在头文件中查看泛型注释。它可以帮助您构建正确的请求对象。