Tag Archives: Swift

Using Optional Values in Swift

Optional Values

Swift has a nil keyword that is sort of like the None keyword in Python; however, regular variables and constants cannot be nil. In order for a variable to be nil, it must be initialized as an optional. (Constants cannot be nil or optional.) An optional is decalred by appending a question mark the variable type. For example, the two statements below are equivalent.

Continue reading