Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Search Calendar using title property

Hi all!

I'm newbe to iOS programming.

Now i'm try to make an app that permits to the user to make events in one specified calendar.

The problem is that:

I cant find a solution to know if there's a calendar with the title that i want to use.

If the list is empty i write a code that create the calendar but if the list isn't empty i need to know if there's a calendar with the calendar.title that i need.

If there isn't i create the calendar if there i i add the event to this calendar.


I post the code below:


EKEvent *myEvent;

EKEventStore *store;

EKSource* localSource;

EKCalendar* newCal;


store = [[EKEventStore alloc] init];

myEvent = [EKEvent eventWithEventStore: store];

NSString* title = [arguments objectAtIndex:1];

NSString* location = [arguments objectAtIndex:2];

NSString* message = [arguments objectAtIndex:3];

NSString* startDate = [arguments objectAtIndex:4];

NSString* endDate = [arguments objectAtIndex:5];

NSString* calendarTitle = [arguments objectAtIndex:6];

//NSString* calID = nil;

//int i = 0;


EKCalendar* calendar = nil;

if(calendarTitle == nil){

calendar = store.defaultCalendarForNewEvents;

} else {

NSIndexSet* indexes = [store.calendars indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {

*stop = false;

EKCalendar* cal = (EKCalendar*)obj;

if(cal.title == calendarTitle){

*stop = true;

}

return *stop;

}];


if (indexes.count == 0) {

//if list is empty i haven't calendars then i need to create it

for (EKSource* source in store.sources)

{

if (source.sourceType == EKSourceTypeLocal)

{

localSource = source;

break;

}

}


if (!localSource) return;


newCal = [EKCalendar calendarWithEventStore:store];

calendar.source = localSource;

calendar.title = calendarTitle;


NSError* error;

bool success = [store saveCalendar:newCal commit:YES error:&error];


if (error != nil)


{

NSLog(error.description);

}

//calendar created


} else {


//!Empty List i need to search the calendar with the title = calendarTitle

//And if there isn't i need to create it




//calendar = [store.calendars objectAtIndex:[indexes firstIndex]];

}

}



Thanks for helping me and sorry for my poor english

iPhone 5, iOS 6

Posted on Jan 25, 2013 8:41 AM

Reply

There are no replies.

Search Calendar using title property

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.