Swift与Lua编程特性深度解析
一、Swift函数调用与参数特性
1.1 方法调用与参数命名
在Swift中,当方法封装在类、结构体或枚举中时,方法的第一个参数名在外部调用时不显示,而后续参数名会显示。例如:
class MyFunClass {
func hello(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.hello("Mr. Roboto", age: 5, location: "San Francisco")
为了提高代码的可读性,建议将第一个参数名包含在方法名中,就像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()
myFunCl
超级会员免费看
订阅专栏 解锁全文
11

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



