swift到现在为止,老实说我还没用到项目中去,因为总是变化,很蛋疼
相对来讲OC更稳定与习惯
但是还是要进行了解,学习swift已备日后使用
swift中的函数,关键字func
直接上语法例子
func rectangleArea(width:Double, _ height:Double, _ cirle:Double) -> Double {
let area = width * height * cirle
return area
}
print("体积为:\(rectangleArea(320, 480,2))")
func singleArea(width:Double, _ height:Double) -> Double{
let valume = width*height/2
return valume
}
print("三角形的面积为:\(singleArea(3,4))")
func des(str1:String, _ str2:String, _ number:Double) -> String
{
return str1 + " is " + str2 + String(number) + " New features"
}
print("拼接的字符串为:\(des("swift","apple ",2.0))")
原文:http://www.cnblogs.com/God-zin/p/4935402.html