2019年6月28日 星期五

iOS swift 5: Function的多參數傳入及回傳



 解決方案來源:
  Function with multiple parameters and multiple return values

func greetUser(name:String, age:Int) -> (String, Int) {
    
    let msg = "Good Morning!" + name
    var userage = age
    if age < 0
    {
     userage = 0
    }
    return (msg, userage)
}
 let msg = greetUser(name: "Jack", age: -2)
 print(msg.0)
 print("You have \(msg.1) coins left")

沒有留言:

張貼留言