Swift 2.xで機能するテストを支援するトリックがありました:UIAlertController
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])
}
}
これは Swift 3.x で失敗しますfatal error: can't unsafeBitCast between types of different sizes
。誰でもそれを理解できますか?