I'm adding new functionality in my app, which is the ability to add an event in the default calendar set up on the phone. I get the permission and am ready to add the event. I check to see if there is an actual default calendar, but I get the error:
Initializer for conditional binding must have Optional type, not 'EKCalendar'
Now, defaultCalendarForNewEvents
is an Optional
(see definition below) and it should be perfectly fine to use optional binding to check if it's nil or not. What am I missing?
defaultCalendarForNewEvents
definition in EKEventStore.h:
open var defaultCalendarForNewEvents: EKCalendar? { get }
I'm using Swift 3 on iOS11.2.(Edited to correct the Swift version I'm using.)
Here's the code:
if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error line
newEvent.title = "Some Event Name"
newEvent.startDate = Date()
newEvent.endDate = Date()
}