/*
複数の戻り値の関数
*/
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 { // error: value of type 'String' has no member 'lowercaseString'
switch String(character).lowercased() {
case "a", "e", "i", "o", "u":
// ++vowels // error: use of unresolved operator '++'; did you mean '+= 1'?
vowels += 1
case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
"n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z":
consonants += 1
default:
others += 1
}
}
return (vowels, consonants, others)
}
// let total = count("some arbitrary string!") // error: missing argument label 'string:' in call
let total = count(string: "some arbitrary string!")
print("total = \(total)")