Swift 注释

2016-05-17  本文已影响16人  JaiUnChat

Apple官方关于文档注释的解释

附上一个例子

/// 初始化一个带边框的圆角按钮
///
/// - parameter button: 需要设置的按钮 类是引用类型
/// - parameter conerRadius: 圆角半径
/// - parameter borderWith: 边框宽度
/// - parameter tintColor: 边框以及文字颜色
func initButton(button: UIButton, conerRadius: CGFloat, borderWith: CGFloat, tintColor: UIColor) {
    button.titleLabel?.tintColor = tintColor
    button.layer.masksToBounds = true
    button.layer.cornerRadius = conerRadius
    button.layer.borderWidth = borderWith
    button.layer.borderColor = tintColor.CGColor
}  

参数多的时候就可以用 - parameters

  /// 初始化一个带边框的圆角按钮
  ///
  /// - parameters:
  ///   - button: 需要设置的按钮 类是引用类型
  ///   - conerRadius: 圆角半径
  ///   - borderWith: 边框宽度
  ///   - tintColor: 边框以及文字颜色

Swift 里的文档注释采用了Markdown

关键词列

关键词大小写都可以
- 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: something else
- Since: iOS 9
- Todo: make it faster
- Version: 1.0.0
- Warning: Don't do it

上一篇 下一篇

猜你喜欢

热点阅读