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

  • Home
  • SEARCH
  • 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 596781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:12:32+00:00 2026-05-13T16:12:32+00:00

I am trying to simplify a switch-statement that takes a lot of space and

  • 0

I am trying to simplify a switch-statement that takes a lot of space and time to write. Se the code, you’ll understand. If not, I’ll explain later.

// When row is selected
- (void)pickerView:(UIPickerView *)pickerTimer didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    switch (row) {
        case 0:
            NSLog(@"It obviously worked.0");
            break;
        case 1:
            NSLog(@"It obviously worked.1");
            break;
        case 2:
            NSLog(@"It obviously worked.2");
            break;
        case 3:
            NSLog(@"It obviously worked.3");
            break;
        case 4:
            NSLog(@"It obviously worked.4");
            break;
        case 5:
            NSLog(@"It obviously worked.5");
            break;
        case 6:
            NSLog(@"It obviously worked.6");
            break;
        default:
            NSLog(@"It did kindof work.NIL");
            break;
    }
}

Is there any way of simplifying this? Just do like,

NSLog(@"It did work! %@", row);

For the record, I tried that, and it did not work.

  • 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-13T16:12:33+00:00Added an answer on May 13, 2026 at 4:12 pm

    The format specifier for an integer is %d — %@ specifies an object. To be safe, you should also cast the NSInteger to an int when you pass it to printf() (so you would write @"%d", (int)row), because the size of NSInteger is not guaranteed to be the size the %d specifier tells printf() to expect.

    Incidentally, you don’t need to repeat it for each case statement. Without a break, control will fall through to the next case.

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

Sidebar

Related Questions

I'm trying to simplify some code where I have an extremely long switch statement
I'm trying to simplify some inherited PHP code that assigns a value to one
I'm trying to simplify some code by putting the ViewModel models into the code
I am trying to figure out how to simplify this piece of code. The
I'm trying to simplify my code, but for some reasons the setText method is
I've trying to simplify a script and it's routines and I'm not quite sure
I am trying to simplify some of the bookmarklets that I have created over
I am trying to simplify (via make_fn() ) the generation of functors that preprocess
I am trying to simplify my code and am moving some of the core
I'm trying to simplify a form (using ASP.NET MVC but I guess that might

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.