Why create "Implicitly Unwrapped Optionals", since that implies you know there's a value?
Asked 07 September, 2021
Viewed 1.2K times
  • 55
Votes

Why would you create a "Implicitly Unwrapped Optional" vs creating just a regular variable or constant? If you know that it can be successfully unwrapped then why create an optional in the first place? For example, why is this:

let someString: String! = "this is the string"

going to be more useful than:

let someString: String = "this is the string"

If ”optionals indicate that a constant or variable is allowed to have 'no value'”, but “sometimes it is clear from a program’s structure that an optional will always have a value after that value is first set”, what is the point of making it an optional in the first place? If you know an optional is always going to have a value, doesn't that make it not optional?

10 Answer