@discussion 到EKEventStore
类EKEventsStore.h
文件说:
"It is generally best to hold onto a long-lived instance of an event store, most likely as a singleton instance in your application."
这里也写了同样的内容:Reading and Writing Calendar Events,在Connecting to the Event Store
部分:
"An EKEventStore object requires a relatively large amount of time to initialize and release. Consequently, you should not initialize and release a separate event store for each event-related task. Instead, initialize a single event store when your app loads, and use it repeatedly to ensure that your connection is long-lived."
所以正确的做法是:
@interface MyEventStore : EKEventStore
+ (MyEventStore *)sharedStore;
@end
+ (MyEventStore *)sharedStore
{
static dispatch_once_t onceToken;
static MyEventStore *shared = nil;
dispatch_once(&onceToken, ^{
shared = [[MyEventStore alloc] init];
});
return shared;
}
@end
并使用它调用[MyEventStore sharedStore]
.
这种方法还修复了警告。