Tag Archives: optional

Optional in swift – what is optional ?

Optional in swift- what is optional in swift ? In swift, a variable either may contain a value or nothing (nil). Put “?” after the variable type. So, to declare such variable, following syntax is used :

Another way to handle optional values is to use the ?? operator