Why do my switch cases sometime need braces in Objective

This question already has an answer here:

  • Why can't variables be declared in a switch statement? 23 answers

  • Basically, if you want to declare a variable you need to add the braces to define scope.

    ARC also adds some requirements (or, rather, stricter requirements) to define scope (so you may get a number of "switch case is in protected scope" errors to fix when upgrading an older codebase). This is because ARC needs to know in detail when a variable isn't / can't be referred to any more so that it can deal with the release correctly.

    Everything relates back to giving the compiler enough information about the scope of declared variables. Should they be part of a single case, or multiple cases...

    链接地址: http://www.djcxy.com/p/14786.html

    上一篇: 为什么我无法在开关盒区块中初始化一个变量

    下一篇: 为什么我的开关盒有时需要在Objective中使用大括号