我刚刚用最后一个Xcode版本打开了一个swift 2项目。 Xcode建议我自动将我的代码转换为swift 3。
这有点奇怪:
func numberOfSections(in tableView: UITableView) -> Int
{
return 1
}
func tableView(_ tableView: MyTableView, numberOfRowsInSection section: Int) -> Int
{
return 10
}
如果你看,Xcode在"中加入了#34; numberOfSections方法的关键字。但他没有为numberOfRowsInSection方法做任何事情。 我不明白为什么。
这是什么"在" Swift 3中的关键字?
答案 0 :(得分:0)
这不是关键字。它是方法中第一个参数的名称。
在Swift2中,方法是......
func numberOfSections(inTableView: UITableView) -> Int
......它会被称为......
numberOfSections(tableView)
在Swift 3中,有很多强调使函数名更基于动词,并从方法名中删除冗余的推断或隐含类型。此外,现在需要方法的第一个参数名称。
所有这些更改都会导致名称更新为您所看到的内容,并且呼叫变为...
numberOfSections(in: tableView)
您可以在Apple's API Guidelines中详细了解Swift 3中的更改。