Hi, Filiz. Are you sure you're using Swift 4 and not the Swift 3 compatibility 
mode? 'defaultCalendarForNewEvents' was marked non-optional in Swift 3 by 
accident and that was fixed in Swift 4.

Jordan


> On Jan 10, 2018, at 08:59, Filiz Kurban via swift-users 
> <swift-users@swift.org> wrote:
> 
> Hello,
> 
> I'm adding a new functionality in my app, which is the ability to add an 
> event in the default calendar set up on the phone. In the implementation, I 
> get the permission and am ready to add the event. I check to see if there is 
> an actual default calendar through the use of optional binding, but I get the 
> error:
> 
> Initializer for conditional binding must have Optional type, not 'EKCalendar'
> 
> Now, defaultCalendarForNewEvents is an Optional (see declaration 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 4 on iOS11.2
> 
> if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error 
> line
>     newEvent.title = "Some Event Name"
>     newEvent.startDate = Date()
>     newEvent.endDate = Date()
> }
> 
> Thank you for your help in advance.
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to