Swift: Add ||= operator

Originator:radexpl
Number:rdar://17569068 Date Originated:
Status: Resolved:
Product: Product Version:
Classification: Reproducible:
 
I'd very much love an easy way to assign a value to an optional variable IF it's nil. Ruby has a ||= operator, which does exactly that.

For example:
foo ||= "default value"

Which basically means:
if !foo {
  foo = "default value"
}

It's super convenient for assigning default values to optional arguments.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!