在Objective C中,我可以使用#pragma mark来标记符号导航器中的代码片段。由于这是一个C预处理器命令,所以在Swift中不可用。在Swift中有替代品吗,或者我必须使用丑陋的评论吗?


当前回答

在Objective-C代码中,Xcode检测像// MARK: - foo这样的注释,它比#pragma更可移植。但这些似乎也没有被采纳(目前?)

编辑:在Xcode 6 beta 4中修复。

其他回答

试试这个:

// MARK: Reload TableView

func reloadTableView(){

    tableView.reload()
}

Add a to-do item: Insert a comment with the prefix TODO:. For example: // TODO: [your to-do item]. Add a bug fix reminder: Insert a comment with the prefix FIXME:. For example: // FIXME: [your bug fix reminder]. Add a heading: Insert a comment with the prefix MARK:. For example: // MARK: [your section heading]. Add a separator line: To add a separator above an annotation, add a hyphen (-) before the comment portion of the annotation. For example: // MARK: - [your content]. To add a separator below an annotation, add a hyphen (-) after the comment portion of the annotation. For example: // MARK: [your content] -.

//# MARK: - Spinner Class Methods

在冒号和描述之间添加一行,以插入分隔线。这有助于更好地组织代码。上面的代码和截图使用了包含一行的MARK注释。

//#标记:-文本方法(LINE) //#标记:文本方法(NO LINE)

这只适用于MARK注释。

在Objective-C代码中,Xcode检测像// MARK: - foo这样的注释,它比#pragma更可移植。但这些似乎也没有被采纳(目前?)

编辑:在Xcode 6 beta 4中修复。

你可能也会对Swift 4.2 / XCode 10编译器指令感兴趣

#warning("Some string to display")

and

#error("Some error to display")

当你真的不想错过什么东西时,它可能会很有用。