Question

I have an iCal file with a rRule: rRule = "FREQ=WEEKLY;UNTIL=20140425T160000Z;INTERVAL=1;BYDAY=TU,TH";

I need to put this info in a EKEvent:

EKEvent *event;
event.recurrenceRules = ...

I split the rRule and save it in NSArray:

 NSArray * rules = [evento.rRule componentsSeparatedByString:@";"];
 event.recurrenceRules = rules;

But an error ocurrs:

-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350'

Can you help me? Thank you for advance.

Was it helpful?

Solution

I found the solution using the EKRecurrenceRule+RRULE library, it's very easy to use.

The link : https://github.com/jochenschoellig/RRULE-to-EKRecurrenceRule

Example to use:

NSString *rfc2445String = @"FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2"; // The 2nd to last weekday of the month

// Result
EKRecurrenceRule *recurrenceRule = [[EKRecurrenceRule alloc] initWithString:rfc2445String];
NSLog(@"%@", recurrenceRule);

OTHER TIPS

When you split the string to an array, you get an array of strings. But the recurrenceRules property expects an array of EKRecurrenceRule objects. You have to parse the strings yourself and transform them into EKRecurrenceRule objects. The following method should be used for complex recurrence rules:

- (id)initRecurrenceWithFrequency:(EKRecurrenceFrequency)type interval:(NSInteger)interval daysOfTheWeek:(NSArray *)days daysOfTheMonth:(NSArray *)monthDays monthsOfTheYear:(NSArray *)months weeksOfTheYear:(NSArray *)weeksOfTheYear daysOfTheYear:(NSArray *)daysOfTheYear setPositions:(NSArray *)setPositions end:(EKRecurrenceEnd *)end

See documentation here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top