iosobjective-cicalendarrfc2445

iOS - iCal rRule in a EKEvent recurrence rule


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.


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);