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 7189235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:15:30+00:00 2026-05-28T19:15:30+00:00

I have a serious long else if statement which contains some links and some

  • 0

I have a serious long else if statement which contains some links and some text.
This is for Xcode 4, iOS 5
EDIT:

stationList = [[NSMutableArray alloc] init];
[stationList addObject:@"Q-dance Radio"];
[stationList addObject:@"The Voice"];
(ect ...)
[stationList sortUsingFunction:compareLetters context:nil];


[tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if ([[stationList objectAtIndex:indexPath.row] isEqual:@"Q-dance Radio"])
    {
        [player pause];
        NSString *u = @"LINK TO Q DANCE RADIO";
        NSURL *url = [NSURL URLWithString:u];
        player = [[AVPlayer alloc] initWithURL:url];
        [player play];
        
    }else if{
        [player pause];
        NSString *u = @"LINK TO THE VOICE";
        NSURL *url = [NSURL URLWithString:u];
        player = [[AVPlayer alloc] initWithURL:url];
        [player play];
        
    } (ect ...)

How can I make this better or make it find the pressed one faster, so it doesn’t need to run though the whole list.

  • 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-28T19:15:32+00:00Added an answer on May 28, 2026 at 7:15 pm

    You could use an NSDictionary, and use the static strings as keys. I think you will get a good speedup from that. (The dictionary look-up probably hashes the input string that you use as a key.)

    If you show more details, I can probably provide a more thorough answer. For example, you could even store the “do something here” code as a ^{} style block.

    UPDATE
    I am at my computer now and can refer to some real code for you. This is based on something I have already done. YOur code may be modified this way:

    xxxList = [[NSMutableArray alloc] init];
    xxxListActionDictionary = [[NSMutableDictionary alloc] initWithCapacity:10];  // add this line
    [xxxList addObject:@"TEXT HERE"];
    [xxxListActionDictionary 
        setObject:
              [[^{
                  // DO SOMETHING HERE. THIS IS A BLOCK. SOME CODE TO BE EXECUTED.
              } copy] autorelease]    // I don't think you need autorelease if you use ARC
        forKey:@"TEXT HERE"];   // TEXT HERE is the same text put into the xxxListArray
    
    ect.
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    // Here is where it gets efficient.
    // The next three lines of code replace the entire if-else if...
    void (^action)(void) = [xxxActionDictionary objectForKey:[[xxxList objectAtIndex:indexPath.row]];  
    if (action != nil) // you want to make sure the key is in the dictionary. may not be needed in your case.
        action();  // this executes the block
    

    UPDATE

    stationList = [[NSMutableArray alloc] init];
    
    [stationList addObject:@"Q-dance Radio"];
    [stationListDictionary setObject:@"http://whateverQDanceRadioIs.com/folder/..." forKey:@"Q-dance Radio"];
    
    [stationList addObject:@"The Voice"];
    [stationListDictionary setObject:@"http://whateverTheVoiceIs.com/folder/..." forKey:@"Q-dance Radio"];
    
    (ect ...)
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    [player pause];
    NSString *u = [stationListDictionary objectForKey[stationList objectAtIndex:indexPath.row]];
    NSURL *url = [NSURL URLWithString:u];
    player = [[AVPlayer alloc] initWithURL:url];
    [player play];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this serious: I have ASP.NET page, This page contents Update panel with
I have a serious performance problem. I have a database with (related to this
Ok guys, I have a serious problem with this. I have a static class
I have a solution with multiple projects and we need to do some serious
In a desktop application needing some serious re-factoring, I have several chunks of code
I have not done any serious C in a long, long time and would
I have a serious probleam with my Eclipse Plugin.. My plugin depends on another
I have a serious problem. One of our servers crashed. Now I reinstalled the
I have a serious issue with crystal reports. when run in my development environment
I have a fairly serious bug in my program - occasional calls to new()

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.