9.4 Implicit Returns from Single Expressions
In the previous example, the return statement was used to return the string value from within the buildMessageFor() function. It is worth noting that if a function contains a single expression (as was the case in this example), the return statement may be omitted. The buildMessageFor() method could, therefore, be rewritten as follows:
func buildMessageFor(name: String, count: Int) -> String {
"\(name), you are customer number \(count)"
}
The return statement can only be omitted if the function contains a single expression. The following code, for example, will fail to compile since the function contains two expressions requiring the use of the return statement:
func buildMessageFor(name: String, count: Int) -> String {
let uppername = name.uppercased()
"\(uppername), you are...