[問題] 閉包(closure)的語法應用
最近開始看書自學 xcode (swift)
之前沒有其他基礎,學得有點辛苦
書籍:ios 10 app 程式設計實力超進化攻略
現在學到UIAlertController
裡面有一段閉包的應用說明:
let callActionHandler = { (action:UIAlertAction!) -> Void in
let alertMessage = UIAlertController(title: "Service Unavailable", message: "Sorry, the call feature is not available yet. Please retry later.", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertMessage, animated: true, completion: nil )
}
書中又教了另一種形式 (上面說推薦,比較簡潔)
但是不是用上面那個設定去介紹
let checkInAction = UIAlertAction(title: "Check in", style: .default, handler:
{
(action:UIAlertAction!) -> Void in
let cell = tableView.cellForRow(at : indexPath)
cell?.accessoryType = .checkmark
})
optionMenu.addAction(checkInAction)
我想了一個晚上一直沒有將第一種轉成第二種的形式
想請問各位該如何將第一種轉成下面那種比較簡潔的語法
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.160.60.120
※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1493736350.A.DBD.html
推
05/03 05:57, , 1F
05/03 05:57, 1F
推
05/03 13:24, , 2F
05/03 13:24, 2F
→
05/03 13:29, , 3F
05/03 13:29, 3F
→
05/03 13:29, , 4F
05/03 13:29, 4F
推
05/03 13:33, , 5F
05/03 13:33, 5F
→
05/03 13:33, , 6F
05/03 13:33, 6F
推
05/03 16:23, , 7F
05/03 16:23, 7F
→
05/03 16:23, , 8F
05/03 16:23, 8F
→
05/03 16:24, , 9F
05/03 16:24, 9F
→
05/03 16:24, , 10F
05/03 16:24, 10F
推
05/03 16:27, , 11F
05/03 16:27, 11F
→
05/03 16:27, , 12F
05/03 16:27, 12F
→
05/03 16:28, , 13F
05/03 16:28, 13F
推
05/03 16:32, , 14F
05/03 16:32, 14F
→
05/03 16:32, , 15F
05/03 16:32, 15F
→
05/03 16:32, , 16F
05/03 16:32, 16F
→
05/03 17:17, , 17F
05/03 17:17, 17F
→
05/04 11:17, , 18F
05/04 11:17, 18F
推
05/05 09:47, , 19F
05/05 09:47, 19F
→
05/05 09:47, , 20F
05/05 09:47, 20F
→
05/08 11:30, , 21F
05/08 11:30, 21F
→
05/08 11:30, , 22F
05/08 11:30, 22F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章