• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Deleting CalTasks through an Array.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Deleting CalTasks through an Array. (From: Joshua Garnham <email@hidden>)

  • Prev by Date: Re: NSRunLoop method - configureAsServer alternative in 10.6.1?
  • Next by Date: poor performance when scrolling scaled text view, with small number of characters per line only
  • Previous by thread: Re: Deleting CalTasks through an Array.
  • Next by thread: Sleep, NSWorkspaceWillSleepNotification, 30 seconds and the run loop
  • Index(es):
    • Date
    • Thread