Is there a standard way to write documentation comment in the Swift language? Something equivalent to javadoc (Java) or docstrings (Python)?
example:
/**
* My docstring example
* @return the String "foo"
*/
func foo() -> String {
return "Foo"
}
Type /// or /** */ to begin a documentation comment and then use DocC's special dialect of Markdown to write the content. This dialect supports many keywords like - Parameters: for describing function arguments or - Returns: for describing return values.
There are two ways to add comments in Swift: // - Single Line comments. /*... */ - Multiline Comments.
6. 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.
Xcode Quick Help Quick Help for a symbol is shown by Option-clicking a symbol. It is also shown in the Quick Help inspector in the utilities area when the insertion point is in a symbol.
Yes there is.
Swift includes "///" comment handling (although probably not everything yet).
Write something like:
/// Hey!
func bof(a: Int) {
}
Then option-click on the func name and voilà :)
There are two types of Documentation comments single line "///..." and multiline "/**...*/" documentations NSHipster explains it here
Sample code copied from the website:
/**
Repeats a string `times` times.
- Parameter str: The string to repeat.
- Parameter times: The number of times to repeat `str`.
- Throws: `MyError.InvalidTimes` if the `times` parameter
is less than zero.
- Returns: A new string with `str` repeated `times` times.
*/
func repeatString(str: String, times: Int) throws -> String {
guard times >= 0 else { throw MyError.InvalidTimes }
return Repeat(count: 5, repeatedValue: "Hello").joinWithSeparator("")
}
EDIT: This solution doesn't work with Swift 2.0.
OLDER solution work until swift 1.2:
I am now trying out the swift language and documentation tool.
The Xcode is very sensitive to indent the text. The keywords must start at the same place.
The keywords must insert beetwen colon, example ":returns:"
If the xcode is not recognized the keyword, then Xcode puts the text into the description.
From this:
/**
Keresés után le lehet kérdezni egy konkrét találatot, pl. ha a harmadikra vagyunk mondjuk kíváncsiak.
:note: n-1 legyen az \p index értéke, mert tömb révén a 0. elemmel keződik a tömb.
:param: aSearchName Keresés meghatározásánál megadott név.
:returns: Konkrét találat. Ha nincs találat, akkor üres stringgel tér vissza a függvégy.
:pre: `aSearchName` != nil && !\p aSearchName != ""
*/
it will be:
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