Re: Deleting CalTasks through an Array.
Re: Deleting CalTasks through an Array.
- Subject: Re: Deleting CalTasks through an Array.
- From: Stamenkovic Florijan <email@hidden>
- Date: Wed, 30 Sep 2009 15:24:59 -0400
On Sep 30, 2009, at 12:32, Joshua Garnham wrote:
I have an Array of strings and want to remove CalTasks with titles
of any of the strings.
I know I can loop through a array with
for(NSString *title in array) {
}
and delete tasks with
removeTask:title error:nil
But it won't let me delete a CalTask object with the strings from
the Array instead it wants the actual CalTask object.How would I
delete a CalTask object by matching it's title to a string in an
array?
Joshua,
You need to use CalCalendarStore's method "taskPredicateWithCalendar",
passing it all calendars to get the tasks, then compare titles and
delete if necessary.
// make a predicate for all tasks
NSPredicate* allCalendarsTaskPredicate = [CalCalendarStore
taskPredicateWithCalendar:[CalCalendarStore calendars]];
// fetch all the tasks
NSArray* allTasks = [[CalCalendarStore defaultCalendarStore]
tasksWithPredicate:allCalendarsTaskPredicate];
// delete them
for(CalTask* task in allTasks)
if([arrayOfTitles contains:tast.title])
// delete task
More or less... Sorry for the typos, I am writing directly to mail.
What would be more efficient and *might* work is creating a compound
predicate out of the allTasks predicate and a predicate that would
discriminate tasks that don't have a matching title. However, I am not
sure that predicate would work with the CalendarStore. Something to
explore if the performance is an issue.
HTH
F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden