• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSOpenPanel runModal on a dispatch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOpenPanel runModal on a dispatch


  • Subject: Re: NSOpenPanel runModal on a dispatch
  • From: Tom Davie <email@hidden>
  • Date: Sun, 16 Dec 2012 15:32:51 +0000

On 16 Dec 2012, at 10:45, Tamas Nagy <email@hidden> wrote:

> Hey,
>
> I'm trying to display an NSOpenPanel on a dispatch, with half-luck. The panel displays, but no files going to be displayed - the circle just spinning on the bottom-left corner. Anyone have an idea what going wrong?
>
> Thanks,
>
> Tamas
>
>    dispatch_async(dispatch_get_main_queue(), ^{
>
>        NSOpenPanel *oPanel = [NSOpenPanel openPanel];
>
>        NSMutableArray *filetype = [NSMutableArray arrayWithCapacity:0];
>
>        [filetype insertObject:@"txt" atIndex:0];
>
>        [oPanel setAllowedFileTypes:filetype];
>        [oPanel setDirectoryURL:[NSURL URLWithString:NSHomeDirectory()]];
>
>
>        NSInteger returnCode = [oPanel runModal];
>
>        if (returnCode == NSOKButton) {
>
>            NSLog(@"OK!");
>
>        } else {
>
>            NSLog(@"Cancel!");
>        }
>
>    });

I can't see off the top of my head what's going wrong here, but I just thought I'd comment that that looks like a pretty bizarre way of creating a constant array.

1) You know exactly how big the array's going to be – 1 object, so why hint that it's going to contain 0 objects?
2) Why use insertObject: atIndex:0 rather than addObject:
3) Why use a mutable array at all?  You could just use a constant array – NSArray *filetype = [NSArray arrayWithObject:@"txt"];
4) The above can then be further condensed with the new syntactic sugar for arrays: NSArray *filetype = @[ @"txt" ];

Thanks

Tom Davie
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSOpenPanel runModal on a dispatch
      • From: Tamas Nagy <email@hidden>
References: 
 >NSOpenPanel runModal on a dispatch (From: Tamas Nagy <email@hidden>)

  • Prev by Date: NSOpenPanel runModal on a dispatch
  • Next by Date: Re: NSOpenPanel runModal on a dispatch
  • Previous by thread: NSOpenPanel runModal on a dispatch
  • Next by thread: Re: NSOpenPanel runModal on a dispatch
  • Index(es):
    • Date
    • Thread