微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift和OC代码注释分析 #pragma mark, FIXME and TODO

转载:http://www.tuicool.com/articles/JVZjmm

While coding in Objective-C,#pragma mark isvery handyfor code organization in the Jump Bar. For example:

#pragma mark – Initialization code here... 
#pragma mark – Table Managementmore code here...

The Jump Bar would show the following,where code sections are clearly marked:

#pragma mark Alternative for Swift

Xcode 6 Now supports a similar feature using// MARK:

// MARK: - Initializationcode here... 
// MARK: - View Managementmore code here...

With the result being:

The “-” after// MARK:is optional,including the “-” results the divider line shown just above the text.

// Todo: in Swift

Although not used as frequently (at least from my perspective),but handy none-the-less are FIXME and Todo. The later is nice when you need to set a reminder for code that you need to revisit.

override func viewDidLoad(){
  super.viewDidLoad()
 
  // Todo: add configuration code
  self.configureView()}

You can also add Todo: outside a method as shown below:

// Todo: revisit memory management handlingfunc setupMemoryRecoveryCode(){}

Notice in the screenshot below that the Todo: references appear at different levels – the first Todo: is indented,indicating it is referencing something to do inside the method itself.

// FIXME: in Swift

// FIXME: works in a similar manner,as it can be place either inside or out of a method.

For example,I’ll often place a // FIXME: with a bug reference once I track down the location of the problem. This gives me a marker and I can quickly return to the issue later.

override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
  // FIXME: - Bug 2102
  let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as UITableViewCell  let object = objects[indexPath.row] as NSDate
  cell.textLabel.text = object.description  return cell}

The output in the Jump Bar looks as follows:

原文地址:https://www.jb51.cc/swift/324152.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐