36

我有一个随该方法NSArray返回的 CalEvents 。[CalCalendarStore eventPredicateWithStartDate]从返回的事件中,我试图只保留事件标题 == @"on call"(不区分大小写)的那些。

我可以将标题包含 @"on call"以下代码的事件保留在数组中(其中“事件”是填充有 的“NSArray” CalEvents):

NSPredicate *onCallPredicate = [NSPredicate predicateWithFormat:@"(SELF.title CONTAINS[c] 'on call')"];
[events filteredArrayUsingPredicate:onCallPredicate];

我尝试过使用谓词格式字符串,例如:

@"SELF.title == 'on call'"但这似乎不起作用。

有没有更简单的方法来做到这一点?

4

2 回答 2

107

尝试[NSPredicate predicateWithFormat:@"title ==[c] 'on call'"];

(这[c]使得相等比较不区分大小写。)

于 2010-06-03T15:35:38.560 回答
10

尝试使用 format 谓词@"self.title like[c] 'on call'"。以下示例代码输出 2 个字符串:

NSArray* ar = [NSArray arrayWithObjects:@"on call", @"I'm on call", @"lala", @"On call", nil];
NSArray* filt = [ar filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self like[c] 'on call'"]];
NSLog([filt description]);

//Output
"on call",
"On call"
于 2010-06-03T15:37:42.743 回答