EKCalendarEvent.title claims to be non-null but it can be, which results in a crash

I am developing a calendar app and I've run into a problem with the way EKCalendarEvents handle titles in Swift.


In Swift 1.2 the title property has the type String!.


This leads one to think that the title can not be null, however, this is not the case. It is possible to create an event with null title using Outlook calendar (simply create an event, do not change anything and save). This will produce an event with no title.


Reading this by writing


let eventTitle = someEKEvent.title


will lead to a crash, one must test for an empty title by using


if let eventTitle = someEKEvent.title {
   // ...
}

I have not yet used this API in Swift 2.0, but I can see that the title property has been declared _Nonnull and the Swift type is now a plain String.


My question is: Is this a bug in the Swift API? Does the new Obejctive-C code replace missing titles with empty strings now? Should I make a new radar?


I am new to the forums, please feel free to correct me if there are any issues with my question.


Thank you

Answered by DTS Engineer in 36150022

It is possible to create an event with null title using Outlook calendar (simply create an event, do not change anything and save).

Quite. If that's the case then either the EKCalendarEvent implementation needs to be fixed (so it doesn't return nil in this case) or its header needs to change (so it doesn't claim to not return nil).

Please file a bug about this, then post your bug number here, just for the record.

I am new to the forums, please feel free to correct me if there are any issues with my question.

You're doing well so far (-:

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

It is possible to create an event with null title using Outlook calendar (simply create an event, do not change anything and save).

Quite. If that's the case then either the EKCalendarEvent implementation needs to be fixed (so it doesn't return nil in this case) or its header needs to change (so it doesn't claim to not return nil).

Please file a bug about this, then post your bug number here, just for the record.

I am new to the forums, please feel free to correct me if there are any issues with my question.

You're doing well so far (-:

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi,


thank you for your reply, I have created a new bug report here rdar://22149387


Also, I've realized that I am actually speaking of EKCalendarItem object (as there is no such thing as EKCalendarEvent)


Cheers

--

Jozef

I filed rdar://40009122 as well.


I'm surprised that EventKit didn't receive any update for years. Guess the force unwrap is a result of auto generated code in order to comply swift syntax.

EKCalendarEvent.title claims to be non-null but it can be, which results in a crash
 
 
Q