0 votes
173 views
asked in Swift by
edited by
Hi

  What is mean by Question mark ? in Swift?

2 Answers

0 votes
answered by (8.2k points)

HI

   An optional value either contains a value or contains nil to indicate that the value is missing. Write a question mark (?) after the type of a value to mark the value as optional.

Example:

  • var optionalString: String? = "Hello"

 

0 votes
answered by

he question mark ? is used during the declaration of a property, as it tells the compiler that this property is optional. The property may hold a value or not, in the latter case it's possible to avoid runtime errors when accessing that property by using ?. This is useful in optional chaining (see below) and a variant of this example is in conditional clauses.

Categories

...