Swift closure "partial apply forwarder"

Viewed 10965

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.

2 Answers

Checkout this Q&A from Apple Developer Forum. Tips for you: find the variable that maybe nil and have something to do with Objective-C code. I fixed the bug in mine. Good luck!

Related