Swift standard documentation comment

前端 未结 5 1293
小鲜肉
小鲜肉 2020-12-31 06:18

Is there a standard way to write documentation comment in the Swift language? Something equivalent to javadoc (Java) or docstrings (Python)?

example:



        
5条回答
  •  别那么骄傲
    2020-12-31 06:42

    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("")
    }
    

提交回复
热议问题