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

前端之家收集整理的这篇文章主要介绍了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.

猜你在找的Swift相关文章