是什么导致DynamoDB UpdateItem在Swift中出现致命错误? [英] What Causes DynamoDB UpdateItem to Giv Fatal Error in Swift?
问题描述
我正在使用Swift让我的应用程序更新DynamoDB上的项目。我按照示例 https://github.com /aws/aws-sdk-ios/blob/master/AWSiOSSDKTests/AWSDynamoDBTests.m#L244 ,即-(void)testUpdateItem方法。我的代码如下:
I am using Swift to let my app update an item on DynamoDB. I followed the example https://github.com/aws/aws-sdk-ios/blob/master/AWSiOSSDKTests/AWSDynamoDBTests.m#L244, the "- (void)testUpdateItem" method. My codes are as follows:
var dynamoDB = AWSDynamoDB()
var hashValue: AWSDynamoDBAttributeValue = AWSDynamoDBAttributeValue()
hashValue.S = userID
var updatedValue: AWSDynamoDBAttributeValue = AWSDynamoDBAttributeValue()
updatedValue.S = updatedContent
var updateInput: AWSDynamoDBUpdateItemInput = AWSDynamoDBUpdateItemInput()
updateInput.tableName = kAWSDynamoDBMoEndpointARNTableName
updateInput.key = ["UserID": hashValue]
var valueUpdate: AWSDynamoDBAttributeValueUpdate = AWSDynamoDBAttributeValueUpdate()
valueUpdate.value = updatedValue
valueUpdate.action = AWSDynamoDBAttributeAction.Put
updateInput.attributeUpdates = ["Updated": valueUpdate]
updateInput.returnValues = AWSDynamoDBReturnValue.UpdatedNew
dynamoDB.updateItem(updateInput).waitUntilFinished()
但是,当我运行代码时,它总是返回致命错误:意外发现nil同时展开一个可选值。调查错误,我发现它来自 Swift._fatalErrorMessage(Swift.StaticString,Swift.StaticString,Swift.StaticString,Swift.Uint)->(),其中包含线程1:EXC_BREAKPOINT (代码= EXC_ARM_BREAKPOINT,子代码= 0xe7ffdefe)
However, as I run the codes, it always returns fatal error: unexpectedly found nil while unwrapping an Optional value. Looking into the error, I can find it is from Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.Uint) -> () with Thread 1: EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xe7ffdefe)
我没有使用.continueWithBlock或.continueWithSuccessBlock cuz都无法捕获错误。
I didn't use .continueWithBlock or .continueWithSuccessBlock cuz neither helps to catch the error.
知道为什么吗?谢谢
推荐答案
您需要获取 AWSDynamoDB
的实例,如下所示:
You need to get an instance of AWSDynamoDB
as follows:
let dynamoDB = AWSDynamoDB.defaultDynamoDB()
您正在使用默认的-init
方法,不带任何参数,这会导致 AWSDynamoDB
实例没有 AWSServiceConfiguration
。
You are using the default - init
method without any parameter, and it causes AWSDynamoDB
instance to have no AWSServiceConfiguration
.
这篇关于是什么导致DynamoDB UpdateItem在Swift中出现致命错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!