---
title: "#97: EventKit Alarms 📅⏰"
url: https://littlebitesofcocoa.com/97-eventkit-alarms
author: Jake Marsh
published: 2015-10-06
topics: ["EventKit"]
description: "EventKit Alarms are how we configure notifications and alerts that will be triggered to remind the user about calendar events or reminders."
---

# #97: EventKit Alarms 📅⏰

By Jake Marsh, October 6, 2015. HTML: https://littlebitesofcocoa.com/97-eventkit-alarms

_EventKit Alarms_ are how we configure **notifications** and **alerts** that will be triggered to remind the user about calendar **events** or **reminders**. 

Like in **Bite #96**, we'll use [Timepiece](http:/git.io/timepiece) ([Bite #3](https://littlebitesofcocoa.com/3)) to help us compose **dates**. We'll create an **event** for when our cookies will be done baking. The **event** will start in 12 minutes, and we'll add a new _EKAlarm_ to it that triggers 5 seconds before the **event**. **Alarms** can be created with at **absolute** or **relative** times.

``` swift
let e = EKEvent(eventStore: eventStore)

e.startDate = NSDate() + 12.minutes
e.endDate = e.startDate + 30.seconds
e.calendar = eventStore.defaultCalendarForNewEvents
e.title = "Cookies are Done! 🍪"

e.addAlarm(EKAlarm(relativeOffset: -5.0))

try eventStore.saveEvent(e, span: .ThisEvent)
```

Interestingly, **OS X** is actually ahead of **iOS** here. _EKAlarm_ on **OS X **has more **properties** for configuring a sound to play, an email address to notify and more.

Now when we get to Disneyland, the **alarm** will remind us to head over to . (Just an example, in real life we'd never need the reminder). 

Things get more fun when adding **alarms** to **reminders**. Let's finish by adding an **alarm** to a new **reminder** that triggers when the user arrives somewhere:

``` swift
let reminder = EKReminder(eventStore: eventStore)

reminder.title = "Ride Star Tours“
reminder.calendar = eventStore.defaultCalendarForNewReminders()

let location = EKStructuredLocation(title: "Disneyland")
location.geoLocation = CLLocation(
  latitude: 33.8120918, longitude: -117.9189742
)

let alarm = EKAlarm()

alarm.structuredLocation = location
alarm.proximity = .Enter

reminder.addAlarm(alarm)

try eventStore.saveReminder(reminder, commit: true)
```
