我有一个iCal
文件,其中包含rRule
:
rRule = "FREQ=WEEKLY;UNTIL=20140425T160000Z;INTERVAL=1;BYDAY=TU,TH";
我需要将此信息放在EKEvent
:
EKEvent *event;
event.recurrenceRules = ...
我将rRule
拆分并保存在NSArray
:
NSArray * rules = [evento.rRule componentsSeparatedByString:@";"];
event.recurrenceRules = rules;
但是出现错误:
-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350'
你能帮帮我吗?
谢谢你提前。
答案 0 :(得分:4)
我使用EKRecurrenceRule + RRULE库找到了解决方案,它非常易于使用。
链接:https://github.com/jochenschoellig/RRULE-to-EKRecurrenceRule
使用示例:
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);
答案 1 :(得分:2)
将字符串拆分为数组时,会得到一个字符串数组。但是recurrenceRules
属性需要一组EKRecurrenceRule
个对象。您必须自己解析字符串并将其转换为EKRecurrenceRule
个对象。以下方法应用于复杂的重复规则:
- (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
请参阅文档here