【发布时间】:2017-11-09 19:08:55
【问题描述】:
我进行了快速测试,并试图将闭包作为函数参数传递,但请注意某种“异常”。应用程序没有崩溃,但有问题的行会生成崩溃报告。
视图控制器
import UIKit
class MapViewController: UIViewController {
typealias MapTouchHandler = (String) -> Void
var mapTouchHandlers = Array<MapTouchHandler>()
@IBAction func tapGestureAction(_ sender: UITapGestureRecognizer) {
for handler in mapTouchHandlers {
// This line produces this: "0x000000010c8f8a00 Mediator`partial apply forwarder for reabstraction thunk helper from @callee_owned (@in Swift.String) -> (@out ()) to @callee_owned (@owned Swift.String) -> () at MapViewController.swift"
handler("tap recognized")
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
func subscribeMapTouchEvent(mapTouchHandler: @escaping MapTouchHandler) {
// This line produce this: "0x000000010c8ff910 Mediator`partial apply forwarder with unmangled suffix ".16" at Mediator.swift"
mapTouchHandlers.append(mapTouchHandler)
}
}
中介类
import UIKit
class Mediator {
var mapViewController: MapViewController? {
didSet {
mapViewController?.subscribeMapTouchEvent(mapTouchHandler: self.handleTouchEvent(str:))
}
}
private func handleTouchEvent(str: String) {
print(str)
}
}
感谢任何解决此问题的见解。
【问题讨论】:
-
应用程序是否崩溃?
-
应用不会崩溃
-
那么“生成崩溃报告的违规行”是什么意思?它是编译器错误/警告、运行时错误/警告还是什么?
-
我也有点失落,应用程序没有崩溃,但在曲棍球应用程序中它正在生成崩溃报告:
Thread 0 Crashed: partial apply forwarder for reabstraction thunk helper from @callee_owned (@unowned __C.CGPoint, @owned [__ObjC.MGLFeature]) -> () to @callee_owned (@in (__C.CGPoint, [__ObjC.MGLFeature])) -> (@out ()) (MapViewController.swift:0) -
如果我在
mapTouchHandlers.append(mapTouchHandler)上设置断点,在调试器中我可以看到mapTouchHandler = (() -> () 0x000000010ee7a910 Mediator partial apply forwarder with unmangled suffix ".16" at Mediator.swift。handler("tap recognized")上的断点显示handler = (() -> ()) 0x000000010ee73a00 Mediator partial apply forwarder for reabstraction thunk helper from @callee_owned (@in Swift.String) -> (@out ()) to @callee_owned (@owned Swift.String) -> () at MapViewController.swift