EKCalendarItem/EKEvent and accessing URL property

Hi all,

I’m having a bit of trouble trying to access the URL property of a calendar event. I’ve successfully been able to create and delete calendar events, and also (using EKEvent) access/edit other properties of these events , such as notes, startdate, etc. but it seems there is no URL property in EKEvent. There is one, however, in EKCalendarItem. Problem is, I am getting an unrecognized selector error when trying to pass an event’s identifier to EKCalendarItem. Here’s the code:

set eventStore to current application's EKEventStore's (alloc()'s initWithAccessToEntityTypes:(current application's EKEntityMaskEvent))
set allCalendars to eventStore's calendarsForEntityType:(current application's EKEntityTypeEvent)

repeat with aCalendar in allCalendars
	set aCalendarName to aCalendar's defaultOrganizerNameForNewItems()
	if (aCalendarName as text) is "Test Calendar" then
		set testCalendar to aCalendar
		exit repeat
	end if
end repeat

set endDate to current application's NSDate's |date|()
set startDate to endDate's dateByAddingTimeInterval:-31536000

set calendarArray to {testCalendar}

set aPredicate to eventStore's predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray

set allEvents to eventStore's eventsMatchingPredicate:aPredicate

repeat with anEvent in allEvents
	-- Here is where I want to get the URL of anEvent, but can't get past setting up the EKCalendarItem "calendarItem"
	-- The class reference for EKCalendarItem indicates to use calendarItemWithIdentifier to look up the item by this value, but obviously I'm missing something here.	
	-- The following results in an unrecognized selector error:
	set anIdentifier to (eventIdentifier of anEvent)
	set calendarItem to (current application's EKCalendarItem's calendarItemWithIdentifier:anIdentifier)
	-- Next lines will hopefully be something simple like:
	-- set URL of calendarItem to aURL --(where aURL is a NSURL)
end repeat


it’s indeed very simple, EKEvent is a subclass of EKCalendarItem so it inherits the property URL

repeat with anEvent in allEvents
	set theURL to anEvent's |URL|()
	log theURL
end repeat

two other suggestions:

¢ retrieve the name of the calendar with title() rather than defaultOrganizerNameForNewItems which I’ve never heard about.

 set aCalendarName to aCalendar's title() as text

¢ define testCalendar before the repeat loop to avoid an error in case the calendar could not be found

Thanks for the response and suggestions Stefan! I can retrieve the URL using the example you provided, but can’t seem to write a new one to the event. Shouldn’t |URL|() be expecting a NSURL? The error I’m getting (and I’m nowhere near being an expert on interpreting error messages) suggests to me that I am sending the wrong object type to |URL|()

tell current application's class "NSURL" to set aURL to its URLWithString:"http://www.apple.com"

-- both attempts below fail :(
-- Error: Can't set «class ocid» id «data optr0000000000C8660080600000» to «class ocid» id «data optr000000004082460000600000». (error -10006)

set |URL|() of anEvent to aURL
set anEvent's |URL|() to aURL

actually the “translated” Cocoa syntax is

anEvent's setURL:aURL

Wonderful! Thanks for your help again Stefan! In order for the new URL to be “saved” to the event I needed to:

anEvent's setURL:aURL
eventStore's saveEvent:anEvent span:(current application's EKSpanThisEvent) commit:true |error|:(missing value)

For other properties in calendar events, I have been doing things like the following (and thus is what I tried with |URL|() ):

set title of anEvent to "Test Event"
set notes of anEvent to "Test Notes"
set calendar of anEvent to aCalendar

But perhaps setTitle ,setNotes, setCalendar would be functional too? I couldn’t find any documentation with good examples of working with these properties…

“classic” setter and getter methods are implemented explicitly like in NSButton

aButton's title() --> getter 
aButton's setTitle:newTitle --> setter

the setter and getter methods of property are created automatically.
For example: The naming convention for a property called price is

price() --> getter
setPrice:newPrice --> setter

The benefit in Objective-C is to use dot notation

NSInteger thePrice = object.price; object.price = 12;
which is identical to

NSInteger thePrice = [object price]; [object setPrice:12];