Var serverResponseCode: Int? = 404
// serverResponseCode contains an actual Int value of 404
serverResponseCode = nil
// serverResponseCode now contains no value
Var surveyAnswer: String?
// surveyAnswer is automatically set to nil
It’s the absence of a value of a certain type.
Additional information
- You set an optional variable to a valueless state by assigning it the special value nil.
- If you define an optional variable without providing a default value, the variable is automatically set to nil for you.