NSOpenPanel / NSSavePanel crashes in Swift 3

In Swift 3 / Xcode8.1 / 10.12.2 I am trying to use NSOpenPanel to get a text file with the following code written by DenBeke

  @IBAction func browseFile(sender: AnyObject)

{

  let dialog = NSOpenPanel();

  dialog.title                   = "Choose a .txt file";
  dialog.allowedFileTypes        = ["txt"];

  if (dialog.runModal() == NSModalResponseOK)
  {
     let result = dialog.url // Pathname of the file

     if (result != nil) {
        let path = result!.path
        print("browseFile path: \(path)")
        //filename_field.stringValue = path
     }
  } else {
     // User clicked on "Cancel"
     return
  }

}

The code opens an open dialog box, as expected, and I can select the file. When you click the "Open" button, the application crashes. In the console, I get:

FI_TFloatingInputWindowController object 0x60800009c0c0 is overridden, but already freed; break on objc_overrelease_during_dealloc_error for debugging

When I run the code and open a dialog, in the console I get

[ ] [] URL: file:////ruediheimlicher/Documents/LoggerdataDir/Messungen/, : = BRCloudDocsErrorDomain Code = 12 " :" com.apple.Documents '"UserInfo = {NSDescription = :' com.apple.Documents '}

.

NSOpen NSSave , : Crash .

, Swift3/sierra?

+4
2

<Your Project> -> <Your Target> -> Capabilities -> App Sandbox -> File Access -> User Selected File.

Custom file resolution

+5

[ ] [] URL: file:////ruediheimlicher/Documents/LoggerdataDir/Messungen/, : = BRCloudDocsErrorDomain Code = 12 " :" com.apple.Documents '"UserInfo = {NSDescription = :' com.apple.Documents '}

, iCloud Drive Finder.

  • ( )
  • iCloud Drive

+2

Source: https://habr.com/ru/post/1665025/


All Articles