24
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

Organization

Swiftのドキュメントコメント

メソッドに適切なコメントを書こうと思っても、Option+Command+/で出せるParametersReturns以外は何があったかすら結構忘れがち。

なので、コピペ用にまとめて置こうと思った次第。

import Foundation

/// オブジェクトのサンプル
class SampleObject {

    /// サンプルメソッド
    ///
    /// - Attention: Watch out for this!
    /// - Author: Tim Cook
    /// - Authors:
    ///   John Doe
    ///   Mary Jones
    /// - Bug: This may not work
    /// - Complexity: O(log n) probably
    /// - Copyright: 2016 Acme
    /// - Date: Jan 1, 2016
    /// - experiment: give it a try
    /// - important: know this
    /// - invariant: something
    /// - Note: Blah blah blah
    /// - Precondition: alpha should not be nil
    /// - Postcondition: happy
    /// - Remark: something else
    /// - Requires: iOS 9
    /// - seealso: [Apple web site](www.apple.com)
    /// - Since: iOS 9
    /// - Todo: make it faster
    /// - Version: 1.0.0
    /// - Warning: Don't do it
    ///
    /// - Parameters:
    ///   - paramA: パラメータAの説明
    ///   - paramB: パラメータBの説明
    /// - Returns: 戻り値の説明
    func sampleMethod(paramA: String, paramB: String) -> String {
        return paramA + paramB
    }

}

jazzyでドキュメントとして出力すると、こんな感じになります。

screencapture-file-Users-DaisukeTodate-Documents-workspace-GitHub-JazzySample-docs-Classes-SampleObject-html-2018-06-25-21_59_23.png

ながっ。

コメントを書くのはいい事だけど、何事もほどほどに。

参考

https://qiita.com/y-some/items/8bc06567eee18dfeafbb
https://useyourloaf.com/blog/swift-documentation-quick-guide/

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
24
Help us understand the problem. What are the problem?