Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to fold comments when using Swift in Xcode?

With objective-C multi-line comments could be folded. This does not appear to work with swift files. Is there a way to enable it in XCode?

like image 283
Drew Rosenberg Avatar asked Nov 11 '22 00:11

Drew Rosenberg


1 Answers

No.

Your best bet is to use ;{ /* Comments */ }(). This won't work anywhere but in a playground, main.swift, or inside of a function/method (Anywhere that expressions are allowed).

There's also comments: do { /* Comments */ } which can also be inlined if prefixed with ;

This will let you reliably fold / unfold inline as well as multi-line blocks.... Problems arise when you are in logic blocks though, such as if/else.. You can't put a "foldable" comment AFTER the ifs closing brace and then BEFORE the else statement:

Wont work:

if someBool == false { return } ;{/**/}()
else { print("is true!") }
    

It's ugly as hell, and a good reason to use AppCode alongside Xcode.

We're already at XC8, and it's just ridiculous at this point, alongside refactoring not available.

AppCode supports many of the missing features in Xcode, so it's a good tool to have in an adjacent space or window. You could also use VisualStudio (bootcamp/virtualbox or second computer)...

Other text editors may support this as well, (Vim, Notepad++), but I haven't used them much to know.

like image 197
Fluidity Avatar answered Dec 15 '22 16:12

Fluidity