I have a NSOpenPanel. But I want to make it PDF-files selectable only. I’m looking for something like that:
// NOT WORKING
NSOpenPanel *panel;
panel = [NSOpenPanel openPanel];
[panel setFloatingPanel:YES];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:YES];
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"pdf"]];
int i = [panel runModalForTypes:nil];
if(i == NSOKButton){
return [panel filenames];
}
I hope someboby has a solution.
A couple things I noticed.. change
setCanChooseDirectoriesto NO. When enabled this indicates that folders are valid input. This is most likely not the functionality you want. You might also want to change your allowed file types to[NSArray arrayWithObject:@"pdf", @"PDF", nil]for case sensitive systems.runModalForTypesshould be the array of file types. Change your code to look like this:Swift 4.2: