Ios 我的代码如何产生此崩溃:[NSConcreteData count]:无法识别的选择器发送到实例
我在BugSense中看到了这个崩溃:Ios 我的代码如何产生此崩溃:[NSConcreteData count]:无法识别的选择器发送到实例,ios,objective-c,unrecognized-selector,Ios,Objective C,Unrecognized Selector,我在BugSense中看到了这个崩溃: -[NSConcreteData count]: unrecognized selector sent to instance 0x14e57f10 - NSInvalidArgumentException 在此代码中: + (NSMutableArray *)applyFilters:(NSMutableArray *)theItems fromFilter:(NSDictionary *)filters { NSMutableArra
-[NSConcreteData count]: unrecognized selector sent to instance 0x14e57f10 - NSInvalidArgumentException
在此代码中:
+ (NSMutableArray *)applyFilters:(NSMutableArray *)theItems fromFilter:(NSDictionary *)filters
{
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:theItems];
if ([[filters allKeys] count] > 0)
{
NSMutableArray *tempFilteredItems = [[NSMutableArray alloc] init];
for (NSString *key in [filters allKeys])
{
NSMutableString *convertedKey = [NSMutableString stringWithString:key];
[convertedKey replaceOccurrencesOfString:@" "
withString:@"_"
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [convertedKey length])];
NSArray *tempFilterAttributes = [NSArray arrayWithArray:filters[key]];
for (NSDictionary *item in items)
{
if (![[item[convertedKey] componentsSeparatedByString:@"*"] firstObjectCommonWithArray:tempFilterAttributes])
{
if (![tempFilteredItems containsObject:item])
{
[tempFilteredItems addObject:item];
}
}
}
[items removeObjectsInArray:tempFilteredItems];
[tempFilteredItems removeAllObjects];
}
}
return items;
}
这是怎么发生的
堆栈跟踪是:
CoreFoundation <redacted> + 130
1 libobjc.A.dylib objc_exception_throw + 38
2 CoreFoundation <redacted> + 202
3 CoreFoundation <redacted> + 706
4 CoreFoundation _CF_forwarding_prep_0 + 24
5 CoreFoundation <redacted> + 28
6 Video Games +[Helper applyFilters:fromFilter:] (Helper.m:2862)
7 Video Games -[WishlistViewController loadUp] (WishlistViewController.m:409) + 29303
8 Video Games -[WishlistViewController viewWillAppear:] (WishlistViewController.m:363) + 27955
9 UIKit <redacted> + 374
10 UIKit <redacted> + 612
11 UIKit <redacted> + 572
12 UIKit <redacted> + 44
13 UIKit <redacted> + 184
14 UIKit <redacted> + 380
15 QuartzCore <redacted> + 142
16 QuartzCore <redacted> + 350
17 QuartzCore <redacted> + 16
18 QuartzCore <redacted> + 228
19 QuartzCore <redacted> + 314
20 UIKit <redacted> + 126
21 CoreFoundation <redacted> + 20
22 CoreFoundation <redacted> + 286
23 CoreFoundation <redacted> + 738
24 CoreFoundation CFRunLoopRunSpecific + 524
25 CoreFoundation CFRunLoopRunInMode + 106
26 GraphicsServices GSEventRunModal + 138
27 UIKit UIApplicationMain + 1136
28 Video Games main (main.m:16) + 888911
29 libdyld.dylib <redacted> + 2
CoreFoundation+130
1 libobjc.A.dylib objc_异常_抛出+38
2芯基础+202
3芯基础+706
4 CoreFoundation\u CF\u forwarding\u prep\u 0+24
5核心基础+28
6个视频游戏+[Helper ApplyFilter:fromFilter:](Helper.m:2862)
7个视频游戏-[WishlistViewController加载](WishlistViewController.m:409)+29303
8个视频游戏-[WishlistViewController视图将出现:](WishlistViewController.m:363)+27955
9 UIKit+374
10 UIKit+612
11 UIKit+572
12 UIKit+44
13 UIKit+184
14 UIKit+380
15夸脱矿+142
16夸脱矿+350
17夸脱矿+16
18夸脱矿+228
19夸脱矿+314
20 UIKit+126
21核心基础+20
22核心基础+286
23核心基础+738
24核心基础CFRUNLOOPSCRUN+524
25 CoreFoundation CFRunLoopRunInMode+106
26图形服务GSEventRunModal+138
27 UIKit UIApplicationMain+1136
28视频游戏主机(main.m:16)+888911
29 libdyld.dylib+2
问题与您提供的代码无关。错误消息表示消息count
已发送到类NSConcreteData
,该类与NSData
基本相同,并且此类类方法不存在。我建议您设置一个异常断点(在Xcode中选择左侧断点导航器,单击
+
左下角,然后选择添加异常断点)。当您执行应用程序时,它将在错误指令处停止 编辑(由于您现在提供的堆栈跟踪):
堆栈跟踪确实表明您的方法
applyFilters:fromFilter:
对崩溃负责。在此方法中,消息count
发送的唯一位置是语句[[filters allKeys]count]
。然后看起来count
被发送到NSConcreteData
对象,而不是像您所期望的那样发送到NSArray
对象。一个原因可能是参数过滤器
(应该是NSDictionary
)是另一种类型的对象。因此,当应用程序在异常断点处停止时,请检查实例
过滤器的类 一,。你的代码使用ARC吗?2.你能提供一个完整的堆栈跟踪吗?如果过滤器
是零
,你的条件实际上是如果(0>0)
,这是错误的,因此你的循环将永远不会启动。你也可以添加一个异常断点,这样你就可以知道是哪一行导致了异常。我无法重新设置崩溃。。。我只是通过BugSense从1000个用户中极少的随机崩溃中进入。我无法重新设置崩溃。。。我只是从1000个用户中很少有随机崩溃的情况下通过BugSense进入。我对原始问题进行了编辑并添加了堆栈跟踪。计数调用可能来自其他地方。这将有助于获得一个符号化的回溯(将替换为更有用的东西),并知道哪一行是第2862行。