Google News
logo
Swift - Interview Questions
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.
 
Syntax :
var optionalName : String? = "Chanti"  
if optionalName != nil {  
    print("Your name is \(optionalName!)")  
}
Advertisement