Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case in protected switch [duplicate]

Possible Duplicate:
When converting a project to use ARC what does “switch case is in protected scope” mean?

Got the following xcode: But when i try to put something in case 1 (or empty) it's giving me an error?

Weird problem because i dont know what a protected switch is and how i should fix it. Does anyone has a solution or clue to fix this? Weird..

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     UIViewController *controller;      switch(indexPath.row) {         case 0:             NSLog(@"0");              //create instance of EKEventStore             EKEventStore *eventStore = [[EKEventStore alloc] init];              //creating instance of EKEvent             EKEvent *event  = [EKEvent eventWithEventStore:eventStore];              //setting the appropriate properties of the new event             event.title     = @"Woow";              //event.startDate = [[NSDate alloc] init];                NSDateComponents *myDate2 = [[NSDateComponents alloc] init];             [myDate2 setDay:13];             [myDate2 setMonth:12];             [myDate2 setYear:2011];             [myDate2 setHour:00];             [myDate2 setMinute:34];              event.startDate = [[NSCalendar currentCalendar] dateFromComponents:myDate2];              event.endDate   = [[NSDate alloc] initWithTimeInterval:3600 sinceDate:event.startDate];             event.location = @"game2";             event.notes = @" game";              event.alarms = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:event.startDate]];              [event setCalendar:[eventStore defaultCalendarForNewEvents]];             NSError *error;             [eventStore saveEvent:event span:EKSpanThisEvent error:&error];              break;          case 1:             NSLog(@"1");                       break;           }      {            self.EKController.title = [self.EKList objectAtIndex:[indexPath row]];           }  }   @end 

But an error:

Error

like image 709
Blazer Avatar asked Dec 13 '11 00:12

Blazer


People also ask

What is duplicate case value?

The error: duplicate case value occurs in C programming, if there are two duplicate case values in the switch statement. Consider the below program – In this program, there are two case values, which are same. "Case 2" exists two times in the program.

What is duplicate case label?

Go Up to Error and Warning Messages (Delphi) This error message occurs when there is more than one case label with a given value in a case statement.

What happens if a switch case has no break?

Without break , the program continues to the next labeled statement, executing the statements until a break or the end of the statement is reached. This continuation may be desirable in some situations. The default statement is executed if no case constant-expression value is equal to the value of expression .

How many cases can switch hold?

Standard C specifies that a switch can have at least 257 case statements. Standard C++ recommends that at least 16,384 case statements be supported! The real value must be implementation dependent.


1 Answers

You should wrap each switch statement with {} braces. For example:

switch (someInt) {     case 0:     {         NSLog(@"Case 0");     }     break;     case 1:     {         NSLog(@"Case 1");     }     break; } 

This has been answered already here by the way - When converting a project to use ARC what does "switch case is in protected scope" mean?

like image 102
mattjgalloway Avatar answered Sep 25 '22 20:09

mattjgalloway