Re: NSOpenPanel runModal on a dispatch
Re: NSOpenPanel runModal on a dispatch
- Subject: Re: NSOpenPanel runModal on a dispatch
- From: Tamas Nagy <email@hidden>
- Date: Sun, 16 Dec 2012 16:43:03 +0100
Thanks for the suggestions Tom. I know about that things, but the original code was a bit bigger, where I need a mutable array and other stuff, and just trimmed out for the example.
But to back to on-topic: the code works fine on 10.6.8, the issue happens only on 10.7.5 and 10.8.2. If I call the method with performSelectorOnMainThread… instead of dispatching, everything works fine. Maybe I found a bug.
On Dec 16, 2012, at 4:32 PM, Tom Davie <email@hidden> wrote:
>
> 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