What is mean by Question mark ? in Swift?

0 votes
83 views
asked Jan 12, 2015 in Swift by Easa
edited Jun 29 by admin
Hi

  What is mean by Question mark ? in Swift?

2 Answers

0 votes
answered Jan 12, 2015 by admin (8,115 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 Jun 29 by anonymous

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.

...