-2

Does Swift have a shorthand syntax for substituting default values when trying to access properties on an optional? For example:

let value = anOptional != nil ? anOptional.value : defaultValue

This is not a question about the simple use of the ?? coalescing operator, but a question about a shorthand syntax for assigning from a property on a non-nil optional.

Neal Stublen
  • 815
  • 11
  • 14

1 Answers1

1

You can do this let value = anOptional ?? defaultValue

Breek
  • 1,431
  • 13
  • 24