I created a new OS X Cocoa application using the standard Xcode Swift template (using StoryBoards).
I implemented IBAction in AppDelegate.swift to handle when users select "Open ..." from the "File" menu. If the selected file is a valid image file, I create NSImage, which I then want to display in the ViewController.
@IBAction func openFile(sender: NSMenuItem) { var openPanel = NSOpenPanel() openPanel.beginWithCompletionHandler { (result :Int) -> Void in if result == NSFileHandlingPanelOKButton { if let imageURL = openPanel.URL { let image = NSImage(contentsOfURL: imageURL)
However, I see no way to connect to the ViewController from AppDelegate. I only managed to find offers that I should look at self.window! in AppDelegate, but in AppDelegate there is no such thing as a window.
Thank you Michael Knudsen
xcode cocoa swift macos
Michael knudsen
source share