如何用Swift替换Objective-C中的#pragma mark?有类似功能吗?
大家好!我最近从Objective-C转到Swift,一直找不到熟悉的#pragma mark结构的替代品。在Objective-C中,我经常使用#pragma mark - Lifecycle、#pragma mark - TableView Delegate等来组织大文件中的代码。这在通过Xcode的Jump Bar导航时非常有帮助。
我试过用两个斜杠和空格写// MARK:,但Xcode有时不会在导航栏中显示它。以下是我的代码示例:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
private func setupUI() {
// 界面设置
}
// MARK: - TableView DataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCel