AWS batchGetItem NSInvalidArgumentException JSONKeyPathsByPropertyKey:无法识别的选择器
Posted
技术标签:
【中文标题】AWS batchGetItem NSInvalidArgumentException JSONKeyPathsByPropertyKey:无法识别的选择器【英文标题】:AWS batchGetItem NSInvalidArgumentException JSONKeyPathsByPropertyKey: unrecognized selector 【发布时间】:2014-12-18 18:27:39 【问题描述】:我正在尝试从 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]:无法识别的选择器发送到类 0x10a9930e8” *** 首先抛出调用堆栈: ( 0 核心基础 0x000000010a6ebf35 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010c5b1bb7 objc_exception_throw + 45 2核心基础0x000000010a6f2f4d + [NSObject(NSObject)不识别选择器:] + 205 3 核心基础 0x000000010a64b27c ___forwarding_ + 988 4 核心基础 0x000000010a64ae18 _CF_forwarding_prep_0 + 120 5 触摸仪表板 0x0000000109b1176a -[MTLJSONAdapter initWithModel:] + 490 6 触摸仪表板 0x0000000109b0fc47 +[MTLJSONAdapter JSONDictionaryFromModel:] + 87 7 触摸仪表板 0x00000001099a47c5 +[AZModelUtility JSONDictionaryFromMapMTLDictionary:] + 517 8 TouchDashboard 0x0000000109a91c5b 59+[AWSDynamoDBBatchGetItemInput requestItemsJSONTransformer]_block_invoke_2 + 75 9 TouchDashboard 0x0000000109b21718-[MTLReversibleValueTransformer reverseTransformedValue:] + 88 10 触摸仪表板 0x0000000109b11b90 __32-[MTLJSONAdapter JSONDictionary]_block_invoke + 480 11 CoreFoundation 0x000000010a62d766 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102 12 核心基础 0x000000010a62d66c -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 204 13 触摸仪表板 0x0000000109b1192c -[MTLJSONAdapter JSONDictionary] + 300 14 触摸仪表板 0x0000000109b0fc5b +[MTLJSONAdapter JSONDictionaryFromModel:] + 107 15 TouchDashboard 0x00000001099a6829-[AWSDynamoDB invokeRequest:HTTPMethod:URLString:targetPrefix:operationName:outputClass:] + 313 16 触摸仪表板 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 工作区DidEndTransaction:] + 179 28 FrontBoardServices 0x000000010ebe92a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16 29 核心基础 0x000000010a62153c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 30 核心基础 0x000000010a617285 __CFRunLoopDoBlocks + 341 31 核心基础 0x000000010a616a43 __CFRunLoopRun + 851 32 核心基础 0x000000010a616486 CFRunLoopRunSpecific + 470 33 UIKit 0x000000010b2f6669-[UIApplication_run] + 413 34 UIKit 0x000000010b2f9420 UIApplicationMain + 1282 35 触摸仪表板 0x000000010992ba2e top_level_code + 78 36 触摸仪表板 0x000000010992ba6a 主 + 42 37 libdyld.dylib 0x000000010cd8b145 开始 + 1 38 ??? 0x0000000000000001 0x0 + 1
【问题讨论】:
【参考方案1】:AWSDynamoDBBatchGetItemInput
的requestItems
属性需要是以下键/值对的字典:
NSString
(表名):AWSDynamoDBKeysAndAttributes
(KeysAndAttributes
)
目前,您将NSDictionary
的实例作为值传递。一旦你更新你的代码 sn-p 以使用AWSDynamoDBKeysAndAttributes
,它应该可以工作。
【讨论】:
谢谢,这解决了我的错误!但现在我又得到了一个。我将为它创建另一个问题 - 请查看 Yosuke!以上是关于AWS batchGetItem NSInvalidArgumentException JSONKeyPathsByPropertyKey:无法识别的选择器的主要内容,如果未能解决你的问题,请参考以下文章
Swift:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:无法识别的选择器发送到实例 0x7fb179f12260'