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

前端 未结 8 1295
忘了有多久
忘了有多久 2020-11-29 17:08

When converting a project to use ARC what does \"switch case is in protected scope\" mean? I am converting a project to use ARC, using Xcode 4 Edit -> Refactor -> Convert to

相关标签:
8条回答
  • 2020-11-29 17:28

    For me, the problem started on the middle of a switch and curly brackets did not worked out, unless you have to include {} IN ALL previous case statements. For me the error came when I had the statement

    NSDate *start = [NSDate date];
    

    in the previous case. After I deleted this, then all subsequent case statement came clean from the protected scope error message

    0 讨论(0)
  • 2020-11-29 17:35

    Surround each case itself with braces {}. That should fix the issue (it did for me in one of my projects).

    0 讨论(0)
  • 2020-11-29 17:43

    Hard to be sure without looking at the code, but it probably means there's some variable declaration going on inside the switch and the compiler can't tell if there's a clear path to the required dealloc point.

    0 讨论(0)
  • There are 2 easy ways to solve this issue:

    • You are probably declaring variables. Move the declaration of the variables outside the switch statement
    • Put the whole case block in between curly brackets {}

    The compiler can not calculate the code line when the variables are to be released. Causing this error.

    0 讨论(0)
  • 2020-11-29 17:46

    Surround with braces {} the code between the case statement and the break in each case. It worked on my code.

    0 讨论(0)
  • 2020-11-29 17:51

    Declare the variables outside the switch, then instantiate them inside the case. That worked perfectly for me using Xcode 6.2

    0 讨论(0)
提交回复
热议问题