您可以在 Xcode 中设置代码区域吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/574953/
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
Can you set code regions in Xcode?
提问by Ferdeen
采纳答案by mouviciel
Using Xcode editor, you can collapse or expand any block of code by clicking in the little left margin. Moreover, you can put a mark in any point in the code with:
使用 Xcode 编辑器,您可以通过单击左边的小边距来折叠或展开任何代码块。此外,您可以在代码中的任何点放置一个标记:
#pragma mark
your title as long as you want
#pragma mark
只要你想要你的头衔
Your mark will then appear in the middle popup menu on top of the editor window.
然后,您的标记将出现在编辑器窗口顶部的中间弹出菜单中。
Update: I have found that a duplicate of this question exists here. The answers may be of interest.
更新:我发现这里存在这个问题的副本。答案可能很有趣。
回答by 0xced
You can also use:
您还可以使用:
// MARK: -
or
或者
// MARK: Initialization
which is more portable than #pragma mark.
这比#pragma mark 更便携。
回答by Brock Woolf
回答by bturner
one more option
还有一种选择
#pragma mark - Initialization
回答by Kibernetik
If you want to have a folding zone with a custom section of your code then put your desired code inside braces {
}
, and it will become a folding zone.
如果你想有一个带有自定义代码部分的折叠区,那么把你想要的代码放在大括号内{
}
,它将成为一个折叠区。
But you have to keep in mind that braces also define variables scope, so this code should not have variables declarations which will be used outside these brackets.
但是你必须记住,大括号也定义了变量范围,所以这段代码不应该有将在这些括号外使用的变量声明。
回答by Carter Medlin
Without support for .Net style regions, being able to collapse all your functions is the next best thing.
在不支持 .Net 风格区域的情况下,能够折叠所有功能是下一个最好的事情。
command-option-shift-left arrowto collapse.
command- option- shift-left arrow崩溃。
command-option-shift-right arrowto expand.
command- option- shift-right arrow展开。
Xcode will remember the last state of collapsed functions.
Xcode 会记住折叠函数的最后状态。