• 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: I think I wrongly got "Switch case is in protected scope"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I think I wrongly got "Switch case is in protected scope"


  • Subject: Re: I think I wrongly got "Switch case is in protected scope"
  • From: Antonio Nunes <email@hidden>
  • Date: Sat, 16 Aug 2014 04:31:36 +0100

On 15 Aug 2014, at 23:24, Daryle Walker <email@hidden> wrote:

> A quick glance at StackOverflow says this is done by a variable declaration directly within the switch’s compound statement.  But I don’t think I have one:
>
> //=====
> - (IBAction)openDocument:(id)sender
> {
>     NSOpenPanel * const  panel = [NSOpenPanel openPanel];
>
>     panel.allowsMultipleSelection = YES;
>     panel.delegate = self;
>     [panel beginWithCompletionHandler:^(NSInteger result){
>         switch (result) {
>             case NSFileHandlingPanelOKButton:
>                 [[panel URLs] enumerateObjectsUsingBlock:^(NSURL *obj, NSUInteger idx, BOOL *stop){
>                     id const  browser = [PrBrowserController createPagelessBrowser];
>
>                     [browser showWindow:sender];
>                     [browser loadPage:obj];
>                 }];
>                 break;
>
>             default:
>                 break;
>         }
>     }];
> }
>
> //=====
>
> Some of the responses think it’s a bug.  The article is a couple of years old; the bug still hasn’t been fixed, or did I mess up somewhere?  I guess I’ll work around it with an if-statement.

You do have a variable declaration: within the switch statement: "id const  browser = [PrBrowserController createPagelessBrowser];” You have to put braces around the statements in a case statement, if you’re declaring variables:

            case NSFileHandlingPanelOKButton: {
                [[panel URLs] enumerateObjectsUsingBlock:^(NSURL *obj, NSUInteger idx, BOOL *stop){
                    id const  browser = [PrBrowserController createPagelessBrowser];

                    [browser showWindow:sender];
                    [browser loadPage:obj];
                }];
                } break;

-António


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: I think I wrongly got "Switch case is in protected scope"
      • From: Quincey Morris <email@hidden>
References: 
 >I think I wrongly got "Switch case is in protected scope" (From: Daryle Walker <email@hidden>)

  • Prev by Date: Re: I think I wrongly got "Switch case is in protected scope"
  • Next by Date: Re: I think I wrongly got "Switch case is in protected scope"
  • Previous by thread: Re: I think I wrongly got "Switch case is in protected scope"
  • Next by thread: Re: I think I wrongly got "Switch case is in protected scope"
  • Index(es):
    • Date
    • Thread