I did a quick testing and am trying to pass a closure as function argument, but notice some kind of "exception". The app is not crashing but the offending line generating a crash report.
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)
}
}
Mediator class
import UIKit
class Mediator {
var mapViewController: MapViewController? {
didSet {
mapViewController?.subscribeMapTouchEvent(mapTouchHandler: self.handleTouchEvent(str:))
}
}
private func handleTouchEvent(str: String) {
print(str)
}
}
Appreciate any insight to solve this issue.
If you are referring "self" in a block i recommend you to use weak self, thus you can avoid retain cycle, memory leak and crash.
Example,
getAsynchronousData { [weak self] data in
guard let self = self else { return }
self.yourProperty = data
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With