views:

71

answers:

2

I was wondering how you actually remove objects from the Calender Store, I've looked at the documentation and it only mentions how to add objects but nothing about removing.

How would I remove an object from the calender store?

+2  A: 

How would I remove an object from the calender store?

Buy out their stock!

Serious answer: The CalCalendarStore object responds to two messages that remove a calendar item: one for events, the other for tasks. Use whichever one is appropriate to the item you want to remove.

Peter Hosey
lol. Ah, I didn't see those messages. However when I add the code, it says `removeTask:` undeclared (http://snapplr.com/0qba). I tried adding a calender before it.
Joshua
But to no avail.
Joshua
@joshua - That's just the method declaration inside square brackets. You need to use real parameters and send the message to an object.
Abizern
Joshua: Seriously, go learn Objective-C. Copy and paste is not working for you.
Peter Hosey
Oh, Yeh, I know now, I was a bit tired when I did that. Here's what I've got now: http://snapplr.com/8dwt. I know why I get the error because it is expecting to remove a `CalTask` not an `NSString`, but I have a Array of `NSStrings` which are titles of the `CalTasks` or I have also an Array of `NSObjects` which are the objects related to the `CalTasks`. How would I match the Strings or Objects to the `CalTasks` I want to remove?
Joshua
Why are you identifying tasks by their titles? I don't know if you've tried this, but you can create two tasks with the same text. How will you know which one to remove?
Peter Hosey
Ok, what about with an NSObject, how would I do it with that?
Joshua
A better question, again, is why.
Peter Hosey
A: 

As Peter points out in his comment; it isn't enough to identify a CalTask just by it's title.

So, how do you uniquely identify a task?

If you look at the documentation for CalTask you will see that it is a sub-class. The super-class has a property which you can use to uniquely identify objects of that super-class, and because CalTask is a sub-class, it too has that property.

Have a look at the code that you used to create those tasks in iCal. When you create each task you can inspect its properties for that property and store it in your model. Then, when you come to delete the tasks from iCal, you can use that property to uniquely identify the task that is to be deleted.

I make no apologies for not being more specific in this answer. You'll need to read the documentation and try and write this for yourself. You'll need to make changes in more than one place in your app:

  1. Change the model so that you can store this unique identifier for the tasks you create.
  2. Change the method that you use to create and add task to the Calendar Store so that you get this identifier and store it in your model.
  3. Make use of this identifier when you are trying to identify the tasks in the Calendar store that you want to delete.
Abizern