Swift standard documentation comment

前端 未结 5 1328
小鲜肉
小鲜肉 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:36

    I believe Apple is still changing the syntax. It looks like all the @ keywords are not implemented as of Xcode 6b2, but otherwise it's the same as ObjC.

    So something like what you have would work:

    /**
     * I am a function.
     */
    func randomFn() {}
    

    Although it seems that Swift stops to align the *s. Of course, you don't really need the stars except the first and last, so you can do this:

    /*
      I am a function.
     */
    func randomFn() {}
    

    Both will be picked up by the comment parser so when you 3-finger click on the function name you will see its doc.

    @param, @return worked for beta1 but not beta2, and those keywords crash the parser a lot in beta1, suggesting that Apple is not done with implementing those yet.

提交回复
热议问题