文章

Xcode 文档注释格式

objc 格式

参考链接:https://stackoverflow.com/a/19169271/16991379

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/** First line text.

 Putting \\n doesn't create a new line.\n One way to create a newline is by making sure nothing is on that line. Not even a single space character!

 @a Italic text @em with @@a or @@em.

 @b Bold text with @@b.

 @p Typewritter font @c with @@p or @@c.

 Backslashes and must be escaped: C:\\foo.

 And so do @@ signs: user@@example.com

 Some more text.
 @brief brief text
 @attention attention text
 @author author text
 @bug bug text
 @copyright copyright text
 @date date text
 @invariant invariant text
 @note note text
 @post post text
 @pre pre text
 @remarks remarks text
 @sa sa text
 @see see text
 @since since text
 @todo todo text
 @version version text
 @warning warning text

 @result result text
 @return return text
 @returns returns text


 @code
// code text
while (someCondition) {
    NSLog(@"Hello");
    doSomething();
}@endcode
 Last line text.

 @param param param text
 @tparam tparam tparam text
 */
- (void)myMethod {}

效果图: img

Swift 格式

官方链接:https://developer.apple.com/documentation/xcode/writing-symbol-documentation-in-your-source-files

参考链接:

  • https://stackoverflow.com/a/27766320/16991379
  • https://nshipster.cn/swift-documentation/

Swift 文档注释是差不多可以按照 markdown 格式走的,输入 /// 或者 /** */ 就可以了。也支持类似 NoteAttention 这样的关键字。

1
2
3
4
/// text
///
/// - Attention: attentionText
var maxWidth: CGFloat = 375
本文由作者按照 CC BY-NC-SA 4.0 进行授权