gpt4 book ai didi

IOS/xcode/核心数据 : Implement calendar control using core data

转载 作者:行者123 更新时间:2023-11-29 02:04:25 26 4
gpt4 key购买 nike

IOS新手在这里尝试在我的项目中使用存储在核心数据中的数据实现一个开源日历控件MADay。日历控件不提供访问核心数据的文档。

我猜我需要在从与下面的“事件”数组相对应的核心数据中提取事件后创建一个 NSArray。这就是全部?如果是这样,我该怎么做?

感谢您的任何建议。

这是库中的数据源代码:

- (NSDate *)nextDayForDate:(NSDate *)date;
- (NSArray *)eventKitEventsForDate:(NSDate *)date;
- (NSArray *)eventKitEventsToMAEvents:(NSArray *)eventKitEvents;

@property (readonly) EKEventStore *eventStore;

@end

@implementation MAEventKitDataSource


- (NSArray *)dayView:(MADayView *)dayView eventsForDate:(NSDate *)date
{
return [self eventKitEventsToMAEvents:[self eventKitEventsForDate:date]];
}

- (NSArray *)weekView:(MAWeekView *)weekView eventsForDate:(NSDate *)date
{
return [self eventKitEventsToMAEvents:[self eventKitEventsForDate:date]];
}


- (EKEventStore *)eventStore
{
if (!_eventStore) {
_eventStore = [[EKEventStore alloc] init];
}
return _eventStore;
}


- (NSDate *)nextDayForDate:(NSDate *)date
{
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:1];

return [CURRENT_CALENDAR dateByAddingComponents:components toDate:date options:0];
}

- (NSArray *)eventKitEventsForDate:(NSDate *)startDate
{
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate
endDate:[self nextDayForDate:startDate]
calendars:nil];

NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
return events;
}

- (NSArray *)eventKitEventsToMAEvents:(NSArray *)eventKitEvents
{
NSMutableArray *events = [[NSMutableArray alloc] init];
for (EKEvent *event in eventKitEvents) {
MAEvent *maEvent = [[MAEvent alloc] init];
maEvent.title = event.title;
maEvent.start = event.startDate;
maEvent.end = event.endDate;
maEvent.allDay = event.allDay;

maEvent.backgroundColor = [UIColor colorWithCGColor:event.calendar.CGColor];
maEvent.textColor = [UIColor whiteColor];

[events addObject:maEvent];
}
return events;
}

最佳答案

我自己还没有使用过这个框架,但据我从代码和 EventKit 文档中看到的,它有自己的商店,因此不需要进一步的核心数据处理。

https://developer.apple.com/library/prerelease/ios/documentation/EventKit/Reference/EKEventStoreClassRef/index.html#//apple_ref/occ/instm/EKEventStore/saveCalendar:commit:error :

所以:阅读文档以理解;)

关于IOS/xcode/核心数据 : Implement calendar control using core data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29947182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com