Last active
January 10, 2022 18:21
-
-
Save mhdhejazi/45fdc219f075147ee83bbdb38c48d8cf to your computer and use it in GitHub Desktop.
Use NSOpenPanel from a Mac Catalyst app with the help of Dynamic (https://github.com/mhdhejazi/Dynamic)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// macOS App | |
let panel = NSOpenPanel() | |
panel.beginSheetModal(for: view.window!, completionHandler: { response in | |
if let url: URL = panel.urls.first { | |
print("url: ", url) | |
} | |
}) | |
// Mac Catalyst (with Dynamic) | |
let panel = Dynamic.NSOpenPanel() | |
panel.beginSheetModalForWindow(self.view.window!.nsWindow, completionHandler: { response in | |
if let url: URL = panel.URLs.firstObject { | |
print("url: ", url) | |
} | |
} as ResponseBlock) | |
typealias ResponseBlock = @convention(block) (_ response: Int) -> Void |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UIWindow.nsWindow
is defined as follows (source):