您可以在 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

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

Can you set code regions in Xcode?

objective-cxcode

提问by Ferdeen

When writing c#, in Visual Studio, you can set regionsto group code accordingly. Being new to Xcode I can't seem to find a similar feature.

编写c#时,在Visual Studio中,可以设置区域对代码进行相应的分组。作为 Xcode 的新手,我似乎找不到类似的功能。

采纳答案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 markyour 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

Sorry for being pedantic but it's "Xcode", not "X-Code".

抱歉我太迂腐了,但它是“Xcode”,而不是“X-Code”。

You can for example go:

例如,您可以去:

#pragma mark -

or

或者

#pragma mark Initialization

This will give you this kind of thing:

这会给你这样的事情:

alt text

替代文字

回答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 会记住折叠函数的最后状态。