前端之家收集整理的这篇文章主要介绍了
Swift基础篇——函数,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import UIKit
func say() -> Void
{
print("hello")
}
say()
func say1() -> ()
{
print("hello")
}
say1()
func say2()
{
print("hello")
}
say2()
func sum(num1: Int,num2: Int)
{
print(num1 + num2)
}
sum(10,num2: 20)
func getNumber() -> Int
{
return 998
}
print(getNumber())
func sum2(num1: Int,num2: Int) -> Int
{
return num1 + num2
}
print(sum2(50,31)">50))
func sum3(num1: Int,tag num2: Int)
{
print("num1 = \(num1),num2 = \(num2)")
print(num1 + num2)
}
sum3(20)
func joinString(str1: String,str2: String = "在",str3: String) -> String
{
return str1 + str2 + str3
}
joinString("张三",str2: "北京")
joinString("李四",0)">"深圳")
func swap(inout a: Int,inout b: Int)
{
print("a = \(a),b = \(b)")
let temp = a
a = b
b = temp
print()
}
var x = 10
var y = 20
print("x = \(x),y = \(y)")
swap(&x,b: &y)
print()
func sum4(nums: Int...,temp: Int) -> Int
{
var sum = 0
for i in nums
{
sum += i
}
return sum + temp
}
sum4(1,2,31)">3,temp: 10)
let value = 55
func test()
{
let number = 10
func demo()
{
print("----\(number),\(value)")
}
demo()
}
test()
原文链接:https://www.f2er.com/swift/325664.html