Take a look at the documentation for EKCalendar. It's pretty simple, it has five properties, only one of which is a string called title
. Now if you have multiple calendars on your iPhone and you open iCal's Calendar settings, you can see that all calendars are nicely grouped by another string called account
.
What I can't figure out, is how to do the same, because although you can see the account
when you NSLog
a EKCalendar
instance, you can't access it:
EKCalendar <0x1851b0> {title = Work; type = CalDAV; account = some@addr.ess; allowsModify = YES; color = 0.690196 0.152941 0.682353 1.000000}
There is no account
property, and trying to access the valueForKey:@"account"
isn't working either, unsurprisingly.
So how do I get to that account
property? Such a simple thing, driving me nuts! Help is much appreciated.
Update: since iOS 5.0, EKCalendar has a source
property.
If you use class-dump on the iOS 4.3 (Simulator) SDK, you'll see that there's a read-only method
-(id)accountName
. However, since it's not in the headers, it's unfortunately private API and you can't use it if you want your App to be accepted in the App Store.I recommend that you file an enhancement request with Apple requesting that this method be made public.
Though thinking about it: If you're really desperate, why not parse the output of
-[EKCalendar description]
? It's very very very bad style and it'll probably break in the future, but you might make it through the App Store review ;) In particular if you only use it for grouping and write your code extremely defensive so it doesn't break but simply doesn't group, should the output of thedescription
method be formatted differently.This information is not available in the 4.0 SDK. Have you looked at the developer previews of the forthcoming SDK to see if that might contain more information?
And on iOS6? It seems the private property
[EKCalendar accountName]
vanished. And[EKCalendar description]
does not contain account anymore. :The
[EKCalendar source]
provides aEKSource
object, that has a title but this is not the name I typed when I created the account but seems to be a more generic name, e.g. Exchange, Other, CalDAV.