如何像在 Visual Studio 中那样使用 Xcode 在 Swift 中折叠注释块? [英] How can I fold blocks of comments in Swift using Xcode the way I do it in Visual Studio?

查看:27
本文介绍了如何像在 Visual Studio 中那样使用 Xcode 在 Swift 中折叠注释块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个仅在结合使用 Xcode 和 Swift 时发生的错误.在 Objective-C 中,它似乎工作正常.我发送了一个错误报告,并将发布来自苹果的消息.

It seems to be a bug which only occurs while using Xcode in combination with Swift. In Objective-C it seems to work fine. I sent out a bug report and will post the news from apple.

在 Visual Studio 中编写 C++ 一段时间后,我开始在 Xcode 中编写 Swift 2.

I started programming Swift 2 in Xcode after some time programming C++ in Visual Studio.

但是我找不到像我在 Visual Studio 中那样获得评论的正确方法.

But I can't find a proper way to get the comments the way I did them in Visual Studio.

有时我只是想评论事情,不想再看到它们直到我另有决定所以我有空闲空间思考解决问题的新方法.这样我就不会分心,更容易找到更好的解决方案.如果我找不到更合适的解决方案,我仍然可以使用备份"在几秒钟内.

Sometimes I just want to comment things out and don't want to see them again until I decide otherwise so I have free space to think about a new approach to a problem. In this way I'm not distracted and find a better solution much easier. And if I don't find a more suitable solution I can still the use the "backup" within seconds.

我如何在 Xcode6 和 Xcode7 Beta 中实现这一点——我在 Visual Studio 中已经做到了这一点?

以下是说明 Visual Studio 2015 中的注释的屏幕截图:

Here is a Screenshot which illustrates commenting in Visual Studio 2015:

我只想要这些使用一行代码并且可以轻松打开和取消注释的小片段.

我在任何地方都没有找到解决此问题的方法.我只发现了一些似乎在 版本 Xcode 中工作但不再的方法.在发布之前,请善待并在最新版本的 Xcode 中检查它们,因为我已经得到了一些显然不再有效的方法.

I haven't found a solution for this problem anywhere. I only found some methods which seemed to work in an older version of Xcode but not anymore. Please be so kind and check them in your latest version of Xcode before you post them because I already got some methods which are apparently not longer working.

推荐答案

Swift 和 Objective-C 中的注释折叠在 Xcode 9 中有效,方法是单击注释,然后按 command+选项+.

The folding of comments in both Swift and Objective-C works in Xcode 9, by clicking in the comment and then pressing command+option+.

对于较早的 Xcode 版本,请参阅下面我的原始答案.

For earlier Xcode versions, see my original answer below.

在 Xcode 9 之前的 Xcode 版本中,注释折叠不适用于 Swift,而仅适用于 Objective-C.(并且最初的问题没有指定语言.)为了在 Xcode 8 及更早版本中使用 Objective-C,您需要打开首选项"中文本编辑"下的代码折叠选项:

In Xcode versions before Xcode 9, comment folding didn't work for Swift, but rather only worked for Objective-C. (And the original question didn't specify the language.) And for it to work with Objective-C in Xcode 8 and earlier, you needed to turn on the code folding option under "Text Editing" in "Preferences":

(在 Xcode 9 中,代码折叠始终处于启用状态,并且该选项不会出现在 Preferences 中.)

(In Xcode 9, code folding is always enabled and this option does not appear in Preferences.)

然后你可以通过按command+option+来折叠Objective-C注释(或者在Xcode 9之前的版本中,你可以点击左边距的折叠区域):

Then you can collapse the Objective-C comments by pressing command+option+ (or in Xcode versions prior to 9, you can click in the folding area in the left margin):

这篇关于如何像在 Visual Studio 中那样使用 Xcode 在 Swift 中折叠注释块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆