我做了一个快速测试,并尝试将闭包作为函数参数传递,但注意某种"异常"。该应用程序没有崩溃,但是有问题的行生成崩溃报告。
的ViewController
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)
}
}
欣赏解决此问题的任何见解。
答案 0 :(得分:3)
如果您正在使用在块中引用“自我”,我建议您使用弱自我,例如。 DispatchQueue.main.async { [weak self] in self?.yourProperty = ... }
答案 1 :(得分:1)
从Apple Developer Forum查看此问答答。给您的提示:找到可能nil
的变量并与Objective-C
代码有关。我修好了我的虫子。祝你好运!