AWS batchGetItem NSInvalidArgumentException JSONKeyPathsByPropertyKey:无法识别的选择器

时间:2014-12-18 18:27:39

标签: ios swift amazon-web-services

我试图在Swift应用程序中从DynamoDB获取一些行。在我下面的代码的最后一行,我得到一个NSInvalidArgumentException。我认为一定是因为我的请求格式不正确,但我不知道出了什么问题。在java sdk的文档(batch operation sample)中,他们使用TableKeysAndAttributes,这似乎并不存在于iOS SDK中。

这是我的代码:

 var venueIdAttribute = AWSDynamoDBAttributeValue()
    venueIdAttribute.N = "2164156"

    var venueIdCondition = AWSDynamoDBCondition()
    venueIdCondition.comparisonOperator = .EQ // Hash Key must always be Equals
    venueIdCondition.attributeValueList = [venueIdAttribute]

    var startDateAttribute = AWSDynamoDBAttributeValue()
    var startString = String(format:"%1.0f", lastSyncDate.timeIntervalSince1970 * 1000)
    startDateAttribute.N = String(format:"%1.0f", lastSyncDate.timeIntervalSince1970 * 1000)

    var dateCondition = AWSDynamoDBCondition()
    dateCondition.comparisonOperator = .GT
    dateCondition.attributeValueList = [startDateAttribute];

    var keysArray : NSArray = [["venueId" : venueIdCondition, "dateInterval" : dateCondition]]
    var tableDict : NSDictionary = ["Keys":keysArray]
    var requestMap : NSDictionary = ["myTable":tableDict]

    var request : AWSDynamoDBBatchGetItemInput = AWSDynamoDBBatchGetItemInput()        
    request.requestItems = requestMap
    request.returnConsumedCapacity = AWSDynamoDBReturnConsumedCapacity.Total

    var response : BFTask = dynamoDB.batchGetItem(request)  // This is synchronous

这是错误:

2014-12-18 13:23:17.002 TouchDashboard [8066:503166] + [ NSDictionaryI JSONKeyPathsByPropertyKey]:无法识别的选择器发送到类0x10a9930e8 2014-12-18 13:23:17.010 TouchDashboard [8066:503166] ***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' + [__ NSDictionaryI JSONKeyPathsByPropertyKey]:无法识别的选择器发送到class 0x10a9930e8' ***第一次抛出调用堆栈: (     0 CoreFoundation 0x000000010a6ebf35 __exceptionPreprocess + 165     1 libobjc.A.dylib 0x000000010c5b1bb7 objc_exception_throw + 45     2 CoreFoundation 0x000000010a6f2f4d + [NSObject(NSObject)doesNotRecognizeSelector:] + 205     3 CoreFoundation 0x000000010a64b27c ___ forwarding _ + 988     4 CoreFoundation 0x000000010a64ae18 _CF_forwarding_prep_0 + 120     5 TouchDashboard 0x0000000109b1176a - [MTLJSONAdapter initWithModel:] + 490     6 TouchDashboard 0x0000000109b0fc47 + [MTLJSONAdapter JSONDictionaryFromModel:] + 87     7 TouchDashboard 0x00000001099a47c5 + [AZModelUtility JSONDictionaryFromMapMTLDictionary:] + 517     8 TouchDashboard 0x0000000109a91c5b 59+ [AWSDynamoDBBatchGetItemInput requestItemsJSONTransformer] _block_invoke_2 + 75     9 TouchDashboard 0x0000000109b21718 - [MTLReversibleValueTransformer reverseTransformedValue:] + 88     10 TouchDashboard 0x0000000109b11b90 __32- [MTLJSONAdapter JSONDictionary] _block_invoke + 480     11 CoreFoundation 0x000000010a62d766 __65 - [__ NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] _ block_invoke + 102     12 CoreFoundation 0x000000010a62d66c - [__ NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 204     13 TouchDashboard 0x0000000109b1192c - [MTLJSONAdapter JSONDictionary] + 300     14 TouchDashboard 0x0000000109b0fc5b + [MTLJSONAdapter JSONDictionaryFromModel:] + 107     15 TouchDashboard 0x00000001099a6829 - [AWSDynamoDB invokeRequest:HTTPMethod:URLString:targetPrefix:operationName:outputClass:] + 313     16 TouchDashboard 0x00000001099a6bd9 - [AWSDynamoDB batchGetItem:] + 153     17 TouchDashboard 0x000000010991a0d7 _TFC14TouchDashboard14ViewController9batchSyncfS0_FT_T_ + 10663     18 TouchDashboard 0x0000000109917349 _TFC14TouchDashboard14ViewController11viewDidLoadfS0_FT_T_ + 1161     19 TouchDashboard 0x0000000109917462 _TToFC14TouchDashboard14ViewController11viewDidLoadfS0_FT_T_ + 34     20 UIKit 0x000000010b41ea90 - [UIViewController loadViewIfRequired] + 738     21 UIKit 0x000000010b41ec8e - [UIViewController视图] + 27     22 UIKit 0x000000010b33dca9 - [UIWindow addRootViewControllerViewIfPossible] + 58     23 UIKit 0x000000010b33e041 - [UIWindow _setHidden:forced:] + 247     24 UIKit 0x000000010b34a72c - [UIWindow makeKeyAndVisible] + 42     25 UIKit 0x000000010b2f5061 - [UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628     26 UIKit 0x000000010b2f7d2c - [UIApplication _runWithMainScene:transitionContext:completion:] + 1350     27 UIKit 0x000000010b2f6bf2 - [UIApplication workspaceDidEndTransaction:] + 179     28 FrontBoardServices 0x000000010ebe92a3 __31- [FBSSerialQueue performAsync:] _ block_invoke + 16     29 CoreFoundation 0x000000010a62153c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12     30 CoreFoundation 0x000000010a617285 __CFRunLoopDoBlocks + 341     31 CoreFoundation 0x000000010a616a43 __CFRunLoopRun + 851     32 CoreFoundation 0x000000010a616486 CFRunLoopRunSpecific + 470     33 UIKit 0x000000010b2f6669 - [UIApplication _run] + 413     34 UIKit 0x000000010b2f9420 UIApplicationMain + 1282     35 TouchDashboard 0x000000010992ba2e top_level_code + 78     36 TouchDashboard 0x000000010992ba6a main + 42     37 libdyld.dylib 0x000000010cd8b145 start + 1     38 ??? 0x0000000000000001 0x0 + 1

1 个答案:

答案 0 :(得分:2)

AWSDynamoDBBatchGetItemInput的{​​{1}}属性需要是以下键/值对的字典:

requestItems(表格名称):AWSDynamoDBKeysAndAttributesNSString

目前,您正在传递KeysAndAttributes的实例作为值。更新代码段以使用NSDictionary后,它应该可以正常工作。