默认参数Default

Posted by Genie on June 25, 2020
1
2
3
4
5
6
7
8
9
10
11
12
13
14
func sayHello1(str1: String = "Hello", str2: String, str3: String) {
    print(str1 + str2 + str3)
}

func sayHello2(str1: String, str2: String, str3: String = "World") {
    print(str1 + str2 + str3)
}

func sayHello3(str1: String, str2: String = "Sun", str3: String) {
    print(str1 + str2 + str3)
}
sayHello1(str2: " ", str3: "World")
sayHello2(str1: "Hello", str2: " ")
sayHello3(str1: "Hi", str3: "Come")