Breaking News
Home / iOS / iOS Isuses / Exception :switch case in protective scope (Objective C)

Exception :switch case in protective scope (Objective C)

Exception :switch case in protective scope

Code with Issue

  case kTopicInteractiveScene:

            TopicInteractiveBackgroundLayer *l = [[TopicInteractiveBackgroundLayeralloc] init];

            ModelManager *mm = [ModelManagersharedModelManger];

            l.info = mm.appInfo.topics[[AppConfigManager  getInstance].currentTopic];

            sceneToRun = [l node];

            break;

<!>

Solution

If there is more then one line of code, it should be enclosed in the
block format using the {} braces else it code does not compile and
results in exception.

Fixed  Code

  case kTopicInteractiveScene:
        {

            TopicInteractiveBackgroundLayer *l = [[TopicInteractiveBackgroundLayeralloc] init];

            ModelManager *mm = [ModelManagersharedModelManger];

            l.info = mm.appInfo.topics[[AppConfigManager  getInstance].currentTopic];

            sceneToRun = [l node];

            break;

        }

Single Statement after case clause

In case of single statement {} are not required

 case kMatchingGameScene:

            sceneToRun = [MatchingGameScene node];

            break;

[pb_builder]

Check Also

local variable ‘build_data’ referenced before assignment : TestFlight Error : Failed to upload build.

Scenario Trying to upload build to TestFlight fails in the end. Error local variable ‘build_data’ …

Advertisment ad adsense adlogger