如何创建 NSPredicate 来搜索日历中的事件?

发布于 2024-11-19 13:51:08 字数 458 浏览 3 评论 0原文

我尝试使用以下谓词来搜索日历中的事件,但我得到以下结果 异常“NSInvalidArgumentException”,原因:“谓词不是使用 EKCalendarStore 方法创建的”

//[_sender objectAtIndex:0] is Name of the event and [_sender objectAtIndex:1] is location of the event

NSPredicate *prediction=[NSPredicate predicateWithFormat:@"(SELF contains[cd] %@)", [NSString stringWithFormat: @"%@%@",[_sender objectAtIndex:0],[_sender objectAtIndex:1]]];
NSArray*events=[eventStore eventsMatchingPredicate:prediction];

I tried to use following predicate to search for events in the Calendar but i'm getting the following
exception 'NSInvalidArgumentException', reason: 'predicate was not created with EKCalendarStore methods'


//[_sender objectAtIndex:0] is Name of the event and [_sender objectAtIndex:1] is location of the event

NSPredicate *prediction=[NSPredicate predicateWithFormat:@"(SELF contains[cd] %@)", [NSString stringWithFormat: @"%@%@",[_sender objectAtIndex:0],[_sender objectAtIndex:1]]];
NSArray*events=[eventStore eventsMatchingPredicate:prediction];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

踏月而来 2024-11-26 13:51:08

我按照 EventKit 编程指南并得到了解决方案。

   NSPredicate *prediction=[eventStore predicateForEventsWithStartDate:statedate endDate:enddate calendars:[eventStore calendars]];
   NSArray*events=[eventStore eventsMatchingPredicate:prediction];

I followed the EventKit Programming Guide and got the solution.

   NSPredicate *prediction=[eventStore predicateForEventsWithStartDate:statedate endDate:enddate calendars:[eventStore calendars]];
   NSArray*events=[eventStore eventsMatchingPredicate:prediction];
以往的大感动 2024-11-26 13:51:08

这是一个 Swift 4.0 实现:

import EventKit

let eventStore = EKEventStore()
let datePredicate = eventStore.predicateForEvents(withStart: begin, 
    end: end,
    calendars: eventStore.calendars(for: .event))
let events = eventStore.events(matching: datePredicate)

Here is a Swift 4.0 implementation:

import EventKit

let eventStore = EKEventStore()
let datePredicate = eventStore.predicateForEvents(withStart: begin, 
    end: end,
    calendars: eventStore.calendars(for: .event))
let events = eventStore.events(matching: datePredicate)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文