-
-
Save mchirico/d072c4e38bda61040f91 to your computer and use it in GitHub Desktop.
/* | |
You need to import EventKit | |
import EventKit | |
*/ | |
@IBAction func buttonCalendar(sender: AnyObject) { | |
var eventStore : EKEventStore = EKEventStore() | |
// 'EKEntityTypeReminder' or 'EKEntityTypeEvent' | |
eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: { | |
granted, error in | |
if (granted) && (error == nil) { | |
println("granted \(granted)") | |
println("error \(error)") | |
var event:EKEvent = EKEvent(eventStore: eventStore) | |
event.title = "Test Title" | |
event.startDate = NSDate() | |
event.endDate = NSDate() | |
event.notes = "This is a note" | |
event.calendar = eventStore.defaultCalendarForNewEvents | |
eventStore.saveEvent(event, span: EKSpanThisEvent, error: nil) | |
println("Saved Event") | |
} | |
}) | |
// This lists every reminder | |
var predicate = eventStore.predicateForRemindersInCalendars([]) | |
eventStore.fetchRemindersMatchingPredicate(predicate) { reminders in | |
for reminder in reminders { | |
println(reminder.title) | |
}} | |
// What about Calendar entries? | |
var startDate=NSDate().dateByAddingTimeInterval(-60*60*24) | |
var endDate=NSDate().dateByAddingTimeInterval(60*60*24*3) | |
var predicate2 = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: nil) | |
println("startDate:\(startDate) endDate:\(endDate)") | |
var eV = eventStore.eventsMatchingPredicate(predicate2) as [EKEvent]! | |
if eV != nil { | |
for i in eV { | |
println("Title \(i.title)" ) | |
println("stareDate: \(i.startDate)" ) | |
println("endDate: \(i.endDate)" ) | |
if i.title == "Test Title" { | |
println("YES" ) | |
// Uncomment if you want to delete | |
//eventStore.removeEvent(i, span: EKSpanThisEvent, error: nil) | |
} | |
} | |
} | |
} |
thanks
I noticed you saved the event with the notes. I was able to do this successfully as well as it shows up in my Calendar. However, if I'm trying to retrieve the data and display it on a UITableView. The only thing that isn't accessible is the notes. Is there a trick to gain access to the notes? I noticed you didn't show how to do it either even though you saved it.
Thanks
how to make predicate for title, location,endDate and startDate.if match all things than fetch event.i need in objective c.
How to update and delete event from ekevent calendar in swift?
this error occurs when i try this code " Error getting shared calendar invitations for entity types 3 from daemon " ?
any help
Thanks
What about time zones? Does this take that into consideration?
how can i disable the edit
Its much faster in a background thread.