programing

보호 된 스위치의 케이스

nasanasas 2020. 9. 20. 10:03
반응형

보호 된 스위치의 케이스 [중복]


중복 가능성 :
ARC를 사용하도록 프로젝트를 변환 할 때 "스위치 케이스가 보호 된 범위에 있습니다"란 무엇을 의미합니까?

다음 xcode가 있습니다.하지만 케이스 1 (또는 비어 있음)에 무언가를 넣으려고하면 오류가 발생합니까?

보호 된 스위치가 무엇인지, 어떻게 고쳐야하는지 모르기 때문에 이상한 문제입니다. 누구든지 이것을 고칠 해결책이나 단서가 있습니까? 기묘한..

- (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

그러나 오류 :

Error


각 switch 문을 {}중괄호 묶어야합니다. 예를 들면 :

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

이것은 이미 여기서 답변되었습니다. ARC를 사용하도록 프로젝트를 변환 할 때 "switch case is in protected scope"는 무엇을 의미합니까?


In general, you should never declare variables inside a case body, unless you wrap the case body in {}. Most C compilers will flag that as an error under several circumstances (though often a very obscure-sounding error).

The reason for this is that the compiler can't tell where the scope of the variable ends, and if you have a declaration in the first case body then it looks like the second case is a branch into the middle of the variable's scope, making the compiler wonder how/if it should be initialized.

참고URL : https://stackoverflow.com/questions/8482678/case-in-protected-switch

반응형