Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:54:56+00:00 2026-05-28T22:54:56+00:00

I am using switch statements in Objective-C, and when I nest a switch statement

  • 0

I am using switch statements in Objective-C, and when I nest a switch statement inside another switch statement, a lot of errors are being found by the compiler. So my general question is how do switch statements affect what methods I can call, and what type of behavior is causing the compiler to generate errors?

switch ([indexPath section]) 
{
    case 0:
        cell.textLabel.text = [infoKeysArray objectAtIndex:indexPath.row];
        CountdownFormatter *formatter = [[CountdownFormatter alloc] init];
        switch (indexPath.row) {
            case 0:
                cell.detailTextLabel.text = [formatter stringForCountdownInterval:taskInfo.duration];
                break;
            case 1:
                cell.detailTextLabel.text = [formatter stringForCountdownInterval:taskInfo.elapsedTime];
            default:
                break;
        }
        [formatter release];
        break;
    case 1:
        cell.textLabel.text = [actionsKeysArray objectAtIndex:indexPath.row];
        //NSArray *segments = [NSArray arrayWithObjects:@"Low", @"Medium", @"High", nil];
        switch (indexPath.row) {
            case 0:
                cell.detailTextLabel.text = priority;
                [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
                break;
            case 1:
                [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
                UISwitch *switch = [[UISwitch alloc] init];
                break;
            case 2:

                break;
            default:
                break;
        }
        break;
    case 2:
        cell.textLabel.text = [detailsKeysArray objectAtIndex:indexPath.row];
        break;
    default:
        break;
}

Here is where I am having issues. Why can I not declare a UISwitch inside this nested switch statement? I know I wrote [[UISwitch alloc] init] but the compiler is flagging it as an error. Any reason that would happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:54:57+00:00Added an answer on May 28, 2026 at 10:54 pm

    I can’t say it any better than this answer Why can’t variables be declared in a switch statement?.

    The issue is where/when you are declaring variables and the scope they are in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get a compiler error when using an Objective-C object within a switch statement:
I was reading some switch statements and noticed one using endswitch; . Why or
How to write following statement in c using switch statement in c int i
For as long as I can remember I have avoided using switch statement fall-through.
What's the best practice for using a switch statement vs using an if statement
What is the benefit/downside to using a switch statement vs. an if/else in C#.
I'm programming a simple text-based RPG using a switch statement for a game loop.
When using a switch() statement, you add break; in between separate case: declarations. But
Is there a way I can generate switch statements in jquery/javascript by using some
I'm using Visual Studio 2005. It always wants to format switch statements like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.