What is the meaning of question mark “?” in Swift?

In Swift, question mark “?” is used in property declaration. It tells the compiler that this property is optional. The property may hold a value or not. It avoids runtime errors when accessing that property by using ?. This is useful in optional chaining and a variant of this example is in conditional clauses.

For example:

var optionalName : String? = “John”
if optionalName != nil {
print(“Your name is \(optionalName!)”)
}