ここでは配列を文字列でフィルタリングするテストを示します。私の文字列が含まれていない場合には、文字( ')うまく動作( ')文字の問題で配列をフィルタリングするためのNSPredicate
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'''
に私の文字列を変更しようとするが、それはまだここ
をクラッシュは、クラッシュログ
ですTerminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "SELF contains[c] 'b'''"'
解決方法どんな助けでも大歓迎です。
は多分無関係に役立ちますが、 'contains'は、その結果beginWith'命名されている述語に悪い候補者のように聞こえます... ' – Alladinian
@Alladinianはい、それは私のテストだけです。私はこのコードをhttp://stackoverflow.com/a/25738783/5381331からコピーしています。あなたは訂正のためにありがとうございます –