Swift与Lua函数特性全解析
Swift函数特性
方法命名与参数
在Swift中,为了提高代码的可读性,建议将第一个参数名包含在方法名中,就像Objective - C那样。例如:
class MyFunClass {
func helloWithName(name: String, age: Int, location: String) {
println("Hello \(name). I live in \(location) too. When is your \(age + 1)th birthday?")
}
}
let myFunClass = MyFunClass()
myFunClass.helloWithName("Mr. Roboto", age: 5, location: "San Francisco")
如果出于特殊原因想跳过外部参数名,可以使用下划线 _ 。示例如下:
class MyFunClass {
func helloWithName(name: String, _ age: Int, _ location: String) {
println("Hello \(name). I live in \(location) too. When is your \(age + 1)th birthday?")
}
}
let myFunClass = MyFunClass()
超级会员免费看
订阅专栏 解锁全文
20

被折叠的 条评论
为什么被折叠?



