Update note: The updated version of this article has been published to swiftsenpai.com.

One of the challenges, when picking up Swift, is to understand how optional work. New learners, usually get confused whether they should use ? or ! when dealing with optional.

In this article, I will help you to understand the concept behind optional, by exploring the usage of both ? and ! operators. If you are a beginner in Swift, this article should give you a good overview of how optional work.

For experienced Swift developer, you can use this as a quick reference whenever you have doubt when dealing with optional operators.

That being said, let’s get started! 🚀

Declaration

var myVariable: MyType