presentAsSheet sim as beginSheetModal with return closure ?

Is it possible to simulate the "beginSheetModal" (alert or opensavepanel behaviour) when presenting a view controller from a storyboard "storyboard.instantiateController" with "presentAsSheet" to have a completion closure ?

Replies

All I ended up having to do is set a variable inside the View Controller then the same as any other @escaping closure ...


var completion: ((NSApplication.ModalResponse) -> Void)? = nil

    func openView(handler: @escaping (NSApplication.ModalResponse) -> Void) {
        if let open_view = self.storyboard!.instantiateController(withIdentifier: "openView") as? openVC {
            self.presentAsSheet(open_view)
            open_view.completion = handler
    }

    let handler = self.openViewResponse
    self.openView(handler: handler)

    func openViewResponse(response: NSApplication.ModalResponse) {
        switch response {
        case .OK:
        ...