不是一个真正的答案,但我写了我想象的一个全面的重复事件对象 API 的样子。我认为它很容易实现,你可以很容易地将它保存在 Core Data 中。
// every tuesday and thursday
// every other month
// every first tuesday
@interface Event : NSManagedObject
@property ( nonatomic, copy ) NSDate * when ;
@property ( nonatomic, copy ) NSTimeInterval duration ; // set to 24hrs for all day event
@property ( nonatomic, strong ) NSArray * repeatPatterns ; // array of EventRepeatPattern. (nil/empty means non-repeating)
@property ( nonatomic, copy ) NSDate * endDate ; // when repeats should end
@property ( nonatomic, strong ) NSArray * excludedOccurrences ; // array of Event giving times main event should *not* occur (to allow deleting individual day from repeating schedule)
-(BOOL)occursOnDay:(NSDate*)day ; // does Event have an occurrence on day?
@end
enum EventRepeatWeekdayMask
{
EventRepeatWeekday_Monday
, EventRepeatWeekday_Tuesday
, EventRepeatWeekday_Wednesday
, EventRepeatWeekday_Thursday
, EventRepeatWeekday_Friday
, EventRepeatWeekday_Saturday
, EventRepeatWeekday_Sunday
} ;
enum EventRepeatOrdinal
{
EventRepeatOrdinal_First
, EventRepeatOrdinal_Second
, EventRepeatOrdinal_Third
, EventRepeatOrdinal_Fourth
, EventRepeatOrdinal_Last = -1
} ;
@interface EventRepeatPattern
+(instancetype)every:(NSDateComponents*)interval ;
+(instancetype)on:(EventRepeatWeekdayMask)mask ;
+(instancetype)on:(EventRepeatOrdinal)ordinal weekdays:(EventRepeatWeekdayMask)mask ;
-(BOOL)occursOnDay:(NSDate*)day forEvent:(Event*)event ; // given `event`, does it occur on `day` based on this repeat pattern?
@end