[swift-users] defaultCalendarForNewEvents is defined as optional however can't use optional binding to check if it's nil

Filiz Kurban filiz.kurban at gmail.com
Wed Jan 10 12:21:22 CST 2018


Thanks for your response. I will check that now! In the meantime, is there
a release note that states this? I have a stackover flow question on this
and would love to resolve it.

On Wed, Jan 10, 2018 at 10:13 AM, Jordan Rose via swift-users <
swift-users at swift.org> wrote:

> 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 at 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 at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20180110/1556ca34/attachment.html>


More information about the swift-users mailing list