-1

以下代码片段是从在线教程中检索到的:

typealias TableCellConfigurationBlock = (cell: ScheduleTableViewCell, indexPath: NSIndexPath, session: Session) -> ()

'typealias' 似乎是一个闭包;还是产生 void() 的元组?

但我不知道它在以下函数中是如何工作的:

   func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("ScheduleTableViewCell") as! ScheduleTableViewCell
        let session = sessionForIndexPath(indexPath)
        if let configureBlock = tableCellConfigurationBlock {
            configureBlock(cell: cell, indexPath: indexPath, session: session)
        }
        return cell
    }

解释?
参考?

4

1 回答 1

1
typealias ClosureType = (i: Int, s: String, d: Double)->String

let c1: ClosureType = {
    // has three input parameters 
    // i:Int, s: String, d: Double
    // and returns String
    i, s, d in
    return s + " integer: \(i) and double: \(d)"
}
let c2: ClosureType = {
    $1 + " integer: \($0) and double: \($2)"
}
print(c1(i: 1,s: "You pass in",d: 3.14))
print(c2(i: 1,s: "You pass in",d: 3.14))
/*
You pass in integer: 1 and double: 3.14
You pass in integer: 1 and double: 3.14
*/
于 2015-11-13T17:44:07.923 回答