pow(A,B) //A的B次方
round(A) //对A四舍五入
if a > 2{ //swift 不需要小括号
}
for i in 0..<10 where i%3 == 0{ //where关键字对i进行筛选
}
for i in (0..<10).reversed(){ //对数组进行反转
}
//通常不需要写外部参数,官方文档可能会这么写
func run(meters meter:Int){//meters 外部参数 meter:内部参数
}
run(meters:10) //10 是实参
func run(_ meter:Int){//_ 外部参数 meter:内部参数
}
run(10)
//最常用
func run(meter:Int){//meter:形参
}
run(meters:10) //10 是实参
func playAction(_ sender: Any) {
let index = Int.random(in: 1...7)
let url = Bundle.main.url(forResource: "audio\(index)", withExtension: "wav")
//会抛出异常 在外面要加上 do-catch
do {
player = try AVAudioPlayer(contentsOf: url!)
player.play()
} catch {
print(error)
}
}