加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 02:41:14 所属栏目:百科 来源:网络整理
导读:While coding in Objective-C,#pragma mark isveryhandyfor code organization in the Jump Bar. Forexample: # pragma mark – Initialization code here... # pragma mark – Table Management more code here... The Jump Bar would show the following,w

While coding in Objective-C,#pragma mark isveryhandyfor code organization in the Jump Bar. Forexample:

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

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

#pragma mark Alternative for Swift

Xcode 6 now supports a similar featureusing// 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 thetext.

// 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 whenyou 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 appearat different levels – the first TODO: isindented,indicating it is referencing something to do inside themethod itself.

?

// FIXME: in Swift

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

For example,I’ll often place a // FIXME: with a bug referenceonce I track down the location of the problem. This gives me amarker 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:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读