控制器 A 和 B, 从A push 进来了 B, B 活干完了把作业交给 A
B:
import UIKit
class BlockViewController: UIViewController {
/// 声明一个 Block
var myBlock: ((String) -> ())?
override func viewDidLoad() {
super.viewDidLoad()
//任意位置调用
myBlock?("即将结束")
}
}
A:
override func viewDidLoad() {
super.viewDidLoad()
let vc = BlockViewController()
//在任意位置接收?
vc.myBlock = { message in
print("接收: \(message)")
}
navigationController?.pushViewController(vc, animated: true);
}