【发布时间】:2016-05-19 10:42:47
【问题描述】:
这是我用字符串过滤数组的测试。如果我的字符串不包含 (') 字符,它会很好地工作
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"Nick", @"b'en", @"Adam", @"Melissa", @"arbind", nil];
//NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"SELF contains[c] 'b'"]; -> it work
NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"SELF contains[c] 'b''"]; -> it crash
NSArray *beginWithB = [array filteredArrayUsingPredicate:sPredicate];
NSLog(@"beginwithB = %@",beginWithB);
我也尝试将我的字符串更改为 'b\'' 或 'b''' 但它仍然崩溃
这是崩溃日志
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无法解析格式字符串“SELF contains[c]'b'''”'
如何解决?任何帮助将不胜感激。
【问题讨论】:
-
可能无关紧要,但
contains听起来不适合作为结果名为beginWith...的谓词的候选对象 -
@Alladinian 是的,这只是我的测试,我只是从stackoverflow.com/a/25738783/5381331 复制这段代码。谢谢指正
标签: ios objective-c nspredicate