Update Comments documentation with preferred comment style (#40)

Update Comments.md to include details for the preferred comment style and example usages.
This commit is contained in:
Des Marks 2022-07-18 15:11:04 -07:00 коммит произвёл GitHub
Родитель f8269b765f
Коммит 9d2e4745e2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 58 добавлений и 0 удалений

Просмотреть файл

@ -124,3 +124,61 @@ func loadLastCheckpoint() -> GameState? {
return loadedState
}
```
## Convention: Single line and multi line comment types
Single line and multi line comments in Swift can be written in a few different forms, some of which enable additional features such as markdown to provide richer documentation.
## Rationale
The triple slash style comment, `///`, is preferred for both single line and multi line comments as it allows for the use of markdown inside comments, provides automcomplete and quick help documentation, and is the default for Xcode's docmentation generation. Additional details about the different comment styles can be found in the [official documentation](https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_markup_formatting_ref/index.html#//apple_ref/doc/uid/TP40016497-CH2-SW1).
## Examples
### Bad: single line comment without markdown used for public property description
``` swift
class SomeToolbar: UIView {
// Array holding UIViews shown inside toolbar
public var toolbarItems: [UIView]?
}
```
### Good: single line comment with markdown used for public property description
``` swift
class SomeToolbar: UIView {
/// Array holding `UIView`s shown inside toolbar
public var toolbarItems: [UIView]?
}
```
### Bad: multi-line comment without '///' style comment used for public method description
``` swift
class SomeToolbar: UIView {
/*
Hides the toolbar view.
@param animated: When true, the view will hide with animation
@param completion: Block called after the view is finished hiding
*/
public func hideToolbar(_ animated: Bool, completion: ((Bool) -> Void)?) {
setHidden(true, animated: animated, completion: completion)
}
}
```
### Good: multi-line comment with `///` style comment used for public method description
``` swift
class SomeToolbar: UIView {
/// Hides the toolbar view.
///
/// Parameter animated: When true, the view will hide with animation
/// Parameter completion: Block called after the view is finished hiding
public func hideToolbar(_ animated: Bool, completion: ((Bool) -> Void)?) {
setHidden(true, animated: animated, completion: completion)
}
}
```