objective c - NSOpenPanel in Swift . How to open? -


I have this Objective-C code:

  - (IBAction) selectFileButtonAction: (ID ) Sender {// Open Open Panel ... NSOPanel * OpenPanel = [NSOPanel OpenPenel]; // NSLog (@ "Open Panel"); // Set restrictions / allowances ... [OpenPennel set component selection: No]; [OpenPennelCommunicationDirectories: No]; [OpenPennelCreate Directories: No]; [OpenPell SetCommunication Files: Yes]; // Allow images only ... [openPanel setAllowedFileTypes: [NSImage imageFileTypes]]; The // Open panel as a sheet on the main window ... [openPanel beginWithCompletionHandler: ^ (NSInteger result) {if (result == NSFileHandlingPanelOKButton) {// must be due to get URL (only sanctions) ... For (NSURL * [URL in the OpenPanel URL]) {// Self Redclose Overview 1. Url = url; _thepath = URL; CurrentSelectedFileName = [[URL Path] lastPathComponent]; // [_roundClockView1SatonAdsDisplay: 1]; [Self open editor]; }}}];  

Now I want to write it fast in the same thing. Here's what I have so far:

  @IBAction function selectAnImageFromFile (this: AnyObject) {var openPanel = NSOpenPanel () openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canCreateDirectories = false openPanel .canChooseFiles = true openPanel.beginWithCompletionHandler (handler: (int) -> nil)}  

And here I am stuck. Thanks for the help

  @IBAction function selectAnImageFromFile (this: AnyObject). {Going openPanel = NSOpenPanel () OpenPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canCreateDirectories = false openPanel.canChooseFiles = true Opanpanelkbeginsnpuarnhandlr {(Results) - & gt; Results that are not valid, == NSFileHandlingPanelOKButton {// do then you will // only one URL, definitely 'openPanel.URL' // but otherwise a loop functions}}}  

I'm guessing that you are stuck on the handler part of the full? In any case, it should be okay to handle URL from the Open panel, but if you want me to add more, then comment. :)


Comments