我不得不a trick幫助測試UIAlertController
,在斯威夫特2.X工作:如何在Swift 3中將__NSMallocBlock__轉換爲其基礎類型?
extension UIAlertController {
typealias AlertHandler = @convention(block) (UIAlertAction) -> Void
func tapButtonAtIndex(index: Int) {
let block = actions[index].valueForKey("handler")
let handler = unsafeBitCast(block, AlertHandler.self)
handler(actions[index])
}
}
這不履行斯威夫特3.X與fatal error: can't unsafeBitCast between types of different sizes
,這誘惑我相信有可能是一種方法,使演員的工作。任何人都可以弄明白嗎?
非常有幫助,謝謝! – xytor