Swift与Lua函数特性深度解析
1. Swift函数参数与方法命名
在Swift中,方法命名和参数使用有一些最佳实践。比如,为了让方法的第一个参数更清晰,最好将其名称包含在方法名中。示例代码如下:
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()
myFunClass.h
超级会员免费看
订阅专栏 解锁全文
109

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



