Swift’s Answer to #pragma mark, FIXME and TODO

转载:http://www.th7.cn/Program/c/201408/271216.shtml

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:

Swift #pragma alternative // MARK

#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:

// MARK in Xcode 6

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 codeself.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.

TODO: in Swift Xcode 6

// 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 2102let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCelllet object = objects[indexPath.row] as NSDatecell.textLabel.text = object.descriptionreturn cell}

The output in the Jump Bar looks as follows:

// FIXME: in Xcode 6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值