swift3.0返回值 无返回值 方法

返回值 无返回值 方法
多重输入参数
func halfOpenRangeLength(start: Int, end: Int) -> Int {
return end - start
}
println(halfOpenRangeLength(1, 10))
无参函数
func sayHelloWorld() -> String {
return "hello, world"
}
println(sayHelloWorld())
无返回值函数
func sayGoodbye(personName: String) {
println("Goodbye, (personName)!")
}
sayGoodbye("Dave")
多重返回值函数
count 函数用来计算一个字符串中元音,辅音和其他字母的个数(基于美式英语的标准)。
func count(string: String) -> (vowels: Int, consonants: Int, others: Int) {
var vowels = 0, consonants = 0, others = 0
for character in string {
switch String(character).lowercaseString {
case "a", "e", "i", "o", "u":
++vowels
case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
"n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z":
++consonants
default:
++others
}
}
return (vowels, consonants, others)
}

你可能感兴趣的:(swift3.0返回值 无返回值 方法)