xcode swift 中“#pragma mark -”的等价物是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24104793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:02:24  来源:igfitidea点击:

What is the equivalent of "#pragma mark -" in swift?

xcodeswift

提问by Tomer Even

I want to organize my code by sections. usually I used #pragma mark - Section Namebut when I try to do so in a .swift file it doesn't work.

我想按部分组织我的代码。我通常使用,#pragma mark - Section Name但是当我尝试在 .swift 文件中这样做时,它不起作用。

So my question is if I can somehow enable it and if not what is the way to organize my code in sections in a .swift file?

所以我的问题是我是否可以以某种方式启用它,如果不能,在 .swift 文件中的部分组织我的代码的方法是什么?

回答by B.S.

Use something like that:

使用类似的东西:

// MARK: - UITableViewDataSource

Or use extensions: I love the way how UITableViewDataSourcedelegate is implemented in this answer

或者使用extensions:我喜欢这个答案中UITableViewDataSource委托的实现方式