【发布时间】:2016-10-21 06:43:59
【问题描述】:
Swift 初学者来了。 我正在阅读 Swift 的教科书,发现一个奇怪的表达......这段代码(第二个“let”行)在做什么?请看一下等号和 UITableVIewCell 方法之间的关系。 对我来说,它看起来像“c 不是 nil,它应该是可选的,并且 c 应该被解包......”
(c != nil) ? c!
我很难在互联网(谷歌)中搜索它,因为我无法在搜索引擎中为该问题做出好的搜索关键字。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//create cells in table
let c = tableView.dequeueReusableCellWithIdentifier("table_cell")
let cell = (c != nil) ? c!: UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "table_cell")
return cell
}
【问题讨论】: