Created
June 30, 2014 23:24
-
-
Save genedelisa/f9d350f0ac90cc079f3d to your computer and use it in GitHub Desktop.
Create a calendar event with alarm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var store:EKEventStore = EKEventStore() | |
store.requestAccessToEntityType(EKEntityTypeEvent, | |
completion:{(granted:Bool, error:NSError?) -> Void in | |
if let e = error { | |
println("Error \(e.localizedDescription)") | |
} | |
if granted { | |
println("access granted") | |
var date:NSDate = NSDate.date() | |
var event:EKEvent = EKEvent(eventStore: store) | |
event.title = "Someone's birthday" | |
event.startDate = date | |
event.endDate = date | |
event.allDay = true | |
event.calendar = store.defaultCalendarForNewEvents | |
// 60 seconds before | |
var alarm:EKAlarm = EKAlarm(relativeOffset: -60) | |
event.alarms = [alarm] | |
var err:NSError? | |
store.saveEvent(event, span:EKSpanThisEvent, error:&err) | |
if let se = err { | |
println("could not save \(se.localizedDescription)") | |
} | |
} | |
}) |
How to update the event? and get alarm offset value?
how to create my app name calendar using swift ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for coding this ,,, here is the iOS9 swift 2 update
cheers from colombia Carlos Norena
here its the code
let store:EKEventStore = EKEventStore()