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
/*
*/
There are two ways to add comments in Swift: // - Single Line comments. /*... */ - Multiline Comments.
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.
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.
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: -
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.
The first one is a Markdown comment that goes into QuickHelp.
The second one is just a comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With