Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please tell me the proper use of swift's comment out.

Tags:

xcode

swift

Please tell me the proper use of swift's comment out. The following two are subtly different colors of green on xcode. How do you use it?

No1

/**



 */

No2

/*



 */
like image 825
Ryosuke Hujisawa Avatar asked Oct 28 '17 01:10

Ryosuke Hujisawa


People also ask

How do you comment out in Swift?

There are two ways to add comments in Swift: // - Single Line comments. /*... */ - Multiline Comments.

How do I comment out code in Xcode?

By selecting a few lines of code (pressing ⇧+↑ or ⇧+↓), you can comment a bunch of lines in a single shot with the ⌘ + / shortcut. If the lines are already comments, the same shortcut will uncomment them.

How do you document in Swift?

To use this feature, click on any class, property, function, or part you want to add a document. Then press ⌥ – Option + ⌘ - command + / or Editor > Structure > Add documentation from Xcode's menu. Xcode will generate a document template for you.

What is Mark in Swift?

Consider this MARK comment: // MARK: - A mark comment lives here. The darker gray separator line just above the bolded option in that menu comes from the dash. Additionally, we can achieve this separator line without a comment by simply not having any text after the dash: // MARK: -


2 Answers

The version with two asterisks, as well as an inline comment using three slashes (///), will show up in the generated interface that you can see by choosing "Jump to Generated Interface" from the "Navigate" menu.

The version with only one asterisk, as well as inline comments with only two slashes (//), will be hidden from the generated interface.

The purpose of /** **/ and /// is for you to provide documentation for your APIs, similar to comments in the header files in Objective-C.

like image 191
Charles Srstka Avatar answered Oct 10 '22 10:10

Charles Srstka


The first one is a Markdown comment that goes into QuickHelp.

The second one is just a comment.

like image 31
matt Avatar answered Oct 10 '22 11:10

matt