前端之家收集整理的这篇文章主要介绍了
Swift高级开发语言--函数,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
var str = "Hello,playground"
func hello1() {
print("hello1")
}
func hello2() -> Void {
print("hello2")
}
hello1()
func hello3Name(name:String,name2:String) {
print("你好\(name) and \(name2)")
}
hello3Name("李云龙",name2: "楚云飞")
func hello4Name (mingzi1 name:String,mingzi2 name2:String) {
print("你好\(name) and \(name2)")
}
hello4Name(mingzi1: "李云龙",mingzi2: "楚云飞")
func hello5 (name:String,_ name2:String){
print("你好\(name) and \(name2)")
}
hello5("李云龙","楚云飞")
func hello6 (name:String = "李云龙",name2:String = "楚云飞"){
print("你好\(name) and \(name2)")
}
hello6()
hello6(name2: "仝兴伟")
func byebye1() -> String {
return "xiake"
}
byebye1()
func byebye2(number1:String) -> (Int,Int) {
var num1 = 0
var num2 = 0
for tempStr in number1.characters{
switch tempStr{
case "a","e","i","o","u":
num1++
default:
num2++
}
}
return (num1,num2)
}
byebye2("aasgfas")
func count1 (numbers:Int...) -> Int {
var sum = 0
for num in numbers {
sum += num
}
return sum
}
count1(1,2,33,5,43,3)
func count3 (var a:Int,b:Int) -> Int {
a = a + b
return a
}
var c = 10
c = count3(c,b: 0)
c
func changValue (inout a: Int) {
a++
}
changValue(&c)
c
原文链接:https://www.f2er.com/swift/325628.html