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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:38:31+00:00 2026-06-15T14:38:31+00:00

Instead of using else if like this if([screen isEqualToString :@A]){ } else if(screen isEqualToString:@B){

  • 0

Instead of using else if like this

            if([screen isEqualToString :@"A"]){

               }
             else if(screen isEqualToString:@"B"){

               }

Will it work like this

          switch ([string isEqualToString:screen]){
          case ISA:
          break;

          case ISB:
          break;

          default:
          break;
       }

where ISA and ISB is defined like

       #define ISA [screen isEqualToString:A] and **will it be efficient**
  • 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-06-15T14:38:32+00:00Added an answer on June 15, 2026 at 2:38 pm

    No, I most certainly don’t think so. switch/case is all about numeric if/then/else cases.

    However what you COULD do is the following:

    Write a function and pass it a variable number of arguments (since objective-c implements C look up va_args for the syntax). Pass it the original string and the strings you want to compare to.

    Inside that function, use a ‘for’ loop, which compares the strings one by one until it either reaches the end or finds a match according to your criteria.

    Once either is met, return the index. And that index you can use in switch case.
    A little example:

    switch([self compareStrings:@"FirstString" Options:"@FirstString", @"SecondString"]) {
        case 0: //FirstString
        break;
    
        case 1: //SecondString
        break;
    
        default: //Not found
        break;
    }
    

    That should work. Regarding your function: Be sure to either incorporate an Optioncount, or make the options ‘nil’ terminated, because otherwise the function won’t know when the end is actually reached.

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

Sidebar

Related Questions

Instead of using an interface like this: public interface IStartable { void Start(); void
Instead of using if/else I'd like to use a map to get a concrete
instead of using getParameterByName('Field', PostData) (PostData == $('form').serialize();) I would like to write PostData.Field,
This is pretty much a duplicate question but instead of using Castle Dynamic Proxy
At the moment I'm using the post method like this $.ajax({ type: POST, url:
Is using 50 if-else statements too resource-intensive for one action? I'm doing something like
I have some trivial code that looks like this: SortedDictionary<String, long> d = new
I am sending post request from android to the url using httpclient like this
I'm using Delphi 9's TDictionary generic class. My TDictionary looks like this: g_FileHandlers :
I have a string that contains something like this: ##### abc 'foo' /path/to/filename:1 #####

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.