我有一个NSMutableArray中包含我的系统上的所有日历(如CalCalendar
对象):删除对象从NSMutableArray的
NSMutableArray *calendars = [[CalCalendarStore defaultCalendarStore] calendars];
我想从calendars
删除任何CalCalendar
对象,其标题不包含字符串@"work"
。
我已经试过这样:
for (CalCalendar *cal in calendars) {
// Look to see if this calendar's title contains "work". If not - remove it
if ([[cal title] rangeOfString:@"work"].location == NSNotFound) {
[calendars removeObject:cal];
}
}
该控制台抱怨说:
*** Collection <NSCFArray: 0x11660ccb0> was mutated while being enumerated.
,事情变坏。很明显,你似乎无法按照这种方式做我想做的事,所以任何人都可以提出最好的解决方法吗?
感谢,
我去了'-filterUsingPredicate:'方法。工作非常出色,只需要两行代码!非常感谢。 – Garry 2010-05-30 17:13:39