Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3488140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:14:04+00:00 2026-05-18T11:14:04+00:00

I have a NSOpenPanel. But I want to make it PDF-files selectable only. I’m

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:14:04+00:00Added an answer on May 18, 2026 at 11:14 am

    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. runModalForTypes should be the array of file types. Change your code to look like this:

    // WORKING :)
    NSOpenPanel *panel;
    NSArray* fileTypes = [NSArray arrayWithObjects:@"pdf", @"PDF", nil];
    panel = [NSOpenPanel openPanel];
    [panel setFloatingPanel:YES];
    [panel setCanChooseDirectories:NO];
    [panel setCanChooseFiles:YES];
    [panel setAllowsMultipleSelection:YES];
    [panel setAllowedFileTypes:fileTypes];
    int i = [panel runModal];
    if(i == NSOKButton){
        return [panel URLs];
    }
    

    Swift 4.2:

    let fileTypes = ["jpg", "png", "jpeg"]
    let panel = NSOpenPanel()
    panel.canChooseFiles = true
    panel.canChooseDirectories = false
    panel.allowsMultipleSelection = false
    panel.allowedFileTypes = fileTypes
    panel.beginSheetModal(for: window) { (result) in
        if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
             // Do something with the result.
             let selectedFolder = panel.urls[0]
             print(selectedFolder)
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an encryption application that for now encrypts text-only files. I need
I am writing a status item app that does not have an NSWindow. I
I have an NSImageView which I get an image for from an NSOpenPanel. That
I would like to solicit additional information from the user during the NSOpenPanel but
Like the title states, I need to make my program wait until my NSOpenPanel
I have a Cocoa application that stores a reference to multimedia files (images, videos,
I have an NSOpenPanel and I want to do some validation of the selection
Have a (rather complex) app that works fine on iOS 4 but fails on
Hello.Am new to ios development.What have to do for NSOpenPanel to work in the
have been playing with Cubepoints (wordpress plugin) and have installed the ranks module but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.