
我想按名称过滤数组
Nsstring *Alphabet = [agencyIndex objectAtIndex:indexPath.section]; //---get all states beginning with the letter--- nspredicate *predicate = [nspredicate predicateWithFormat:@"SELF beginswith[c] %@",Alphabet]; NSMutableArray *ListSimpl = [[NSMutableArray alloc] init]; for (int i=0; i<[[Database sharedDatabase].agents count]; i++) { Town *_town = [[Database sharedDatabase].agents objectAtIndex:i]; [ListSimpl addobject:_town]; } NSArray *states = [ListSimpl filteredArrayUsingPredicate:predicate]; 但是我收到一个错误 – “不能做一个不是字符串的东西的子串 *** 作(lhs =< 1,Arrow> rhs = A)”
我该怎么做?我想过滤名字中第一个字母的数组为’A’.
解决方法 尝试以下代码nspredicate *pred = [nspredicate predicateWithFormat:@"SELF like %@",yourname];NSArray *filteredArr = [yourArray filteredArrayUsingPredicate:pred];
编辑:
nspredicate模式应该是:
nspredicate *pred =[nspredicate predicateWithFormat:@"name beginswith[c] %@",Alphabet];总结
以上是内存溢出为你收集整理的ios – 通过字符串属性的第一个字母过滤数组全部内容,希望文章能够帮你解决ios – 通过字符串属性的第一个字母过滤数组所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)