我有一个类和扩展 Swift 文件。将我在另一个文件中声明的委托(delegate)添加到类后,Xcode 显示此错误
Declaration is only valid at file scope
在延长线上。我不知道是什么问题。
谁能帮我解决这个问题?
class ListViewController: UIViewController, AddItemViewControllerDelegate {...}
extension ListViewController: UITableViewDataSource{
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
performSegueWithIdentifier("ShowDetail", sender: indexPath)
}
}
最佳答案
错误在您的 ...
某处 — 该错误意味着您的 ListViewController
类没有关闭,因此扩展被解释为嵌套在其中,像这样:
class ListViewController {
...
extension ListViewController {
}
}
找到丢失的右大括号,你应该解决问题。
关于ios - 关于 "Declaration is only valid at file scope",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28554231/