2011-07-11 29 views
1

我試圖用以下謂詞來搜索日曆事件,但我發現了以下 異常「NSInvalidArgumentException」,原因是:如何創建NSPredicate以在日曆中搜索事件?

 

//[_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]; 

回答

0

「謂詞不是用EKCalendarStore方法創建的」我跟着EventKit編程指南並獲得解決方案。

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

這裏是一個雨燕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)