I attach a screenshot, I first encountered this error, I can not fix it. If there are professionals or craftsmen. Tell me what he wants and how to fix it. I will be very grateful.

enter image description here

  • your selectedEvent.match returns nil, and apparently it is - you haven’t assigned anything to it anywhere - Max Mikheyenko

1 answer 1

You have the selectedEvent variable, which is declared as an Implicitly Unwrapped Optional Type (by adding a '!' At the end of the declaration)

 var selectedEvent : Event! 

What does it mean? that when the program tries to read the value from this variable, it should crash if there is nil

The Swift language defines the postfix! It is a type of syntactic formula. If you try to use an implicitly unwrapped optional, you can get a runtime error.

What is going on with you? exactly what is written in the documentation. In other words, this is the correct behavior of the program.

How to fix it?

1) assign something to a variable before reading from it.

or

2) do not declare it as implicitly unwrapped (remove '!', Or replace with '?')

  • Thank you. For the hint. I already thought of it and remembered what the problem was. Already I try it but in a different line it requires. - ShurikTennisist