アプリでコアデータを使用していますが、
開始文字ですべてのエンティティを検索できます。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name MATCHES '^[hH].*'"];
//sort descriptor!
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSArray *companyProducts = [Company allWithPredicate:predicate sortDescriptors:@[sortDescriptor]];
Company *theCompany;
NSLog(@"tus companies number:: %d", companyProducts.count);
for (theCompany in companyProducts) {
NSLog(@"tus companies:: %@", theCompany.name);
}
したがって、この場合、小文字または大文字に関係なく、hで始まるすべての会社を取得します...
しかし、複数の文字で一致を検索する必要がある場合は? 大文字小文字問わず、
たとえば、次を探します。
ハイパーヒョソン
それで、正規表現を構築する方法を知る必要がありますか? 自分のプロパティで n 個の文字を検索するには?
ありがとう!