Swift functions should return value of last evaluated expression

Originator:kristopherdjohnson
Number:rdar://17139234 Date Originated:03-Jun-2014 11:46 PM
Status:Closed/Works as designed Resolved:Works as designed
Product:Developer Tools Product Version:Xcode 6
Classification:Enhancement Reproducible:n/a
 
Summary:
Swift functions are currently unnecessarily verbose due to the need for an explicit "return" statement. It would be nice if functions could automatically return whatever expression was last evaluated.

For example:

func square(x: Int) -> Int { x * x }  // instead of "return x * x"

or

func oddOrEven(x: Int) -> String {
  if x % 2 == 0 {
    "Even"
  } else {
    "Odd"
  }
}

----

Response from Apple Developer Relations 06-Jun-2014 03:36 PM

Engineering has determined that there are no plans to address this based on the following:

We considered this, but this becomes problematic in many cases.

We are now closing this bug report.

If you have questions regarding the resolution of this issue, please update your bug report with that information.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.

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!