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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to