【发布时间】:2013-09-13 21:50:41
【问题描述】:
我有一个NSArray,其中的对象具有name 属性。
我想通过name 过滤数组
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 = rhs = A)”
我该怎么做?我想过滤name 中第一个字母为“A”的数组。
【问题讨论】:
-
不,我想按第一个字母“A”过滤
-
这篇文章最重要的一段代码是谓词本身,但被忽略了。显示您是如何定义谓词的?
标签: ios objective-c cocoa-touch filter nsarray