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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:19:12+00:00 2026-05-30T04:19:12+00:00

I used the typedef enum below but the switch always return the default case

  • 0

I used the typedef enum below but the switch always return the default case why ?

typedef enum {
    first,
    LatestNews,
    Opinion,
    Special,
    Sports,
    Thisweek,
} NAChannelTitle;

-(NSString *)getImageName:(NSString *)channelName {
    NAChannelTitle temp = (NAChannelTitle)[channelName stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"Temp : %@",temp);
    switch (temp) {
        case first:
            return @"background-channel-sporttitle-portrait.png";
            break;
        case LatestNews:
            return @"background-channel-title-portrait.png";
            break;
        case Opinion:
            return @"background-channel-title-portrait.png";
            break;
        case Special:
            return @"background-channel-sporttitle-portrait.png";
            break;
        case Sports:
            return @"background-channel-sporttitle-portrait.png";
            break;
        case Thisweek:
        default:
            return @"background-channel-title-portrait.png";
            break;
    }
    return nil;
}
  • 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-30T04:19:13+00:00Added an answer on May 30, 2026 at 4:19 am

    You can’t convert a string to enum, since the enums names are not saved, instead, you can create a function that does it, by comparing strings, this is longer, but I don’t think you have other option. a macro may help:

    NAChannelTitle getEnumTitle(NSString *sTitle) {
    #define CHECK_ENUM(X)   if([sTitle isEqualToString:@#X]) return X        
        CHECK_ENUM(first);
        // the same for all enum
        return defaultEnum; // add this to the enum
    #undef CHECK_ENUM
    }
    

    then you may do:

    NAChannelTitle temp = getEnumTitle(channelName);
    NSLog(@"Temp : %d",temp);
    switch (temp) {
        case first:
            return @"background-channel-sporttitle-portrait.png";
            break;
        case LatestNews:
            return @"background-channel-title-portrait.png";
            break;
        case Opinion:
            return @"background-channel-title-portrait.png";
            break;
        case Special:
            return @"background-channel-sporttitle-portrait.png";
            break;
        case Sports:
            return @"background-channel-sporttitle-portrait.png";
            break;
        case Thisweek:
        default:
            return @"background-channel-title-portrait.png";
            break;
    }
    return nil;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've always used typedef in embedded programming to avoid common mistakes: int8_t - 8
Why typedef can not be used with static? For example, the code below is
I've used typedef enum in the past with method parameters and had no problem,
I see NSInteger is used quite often and the typedef for it on the
I have a typedef typedef unsigned int my_type; used in a file. I would
I was getting a little confused with typedef/enum until I realised that I did
Kind of a weird newbie question...I want to use typedef enum declarations in one
This: typedef HRESULT (*PFN_HANDLE)(ClassName&); It's used like this: DWORD ClassName::Wait(PFN_HANDLE pfnh_foo) { while (!done)
In C, I sometimes used structures such as enum { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin
I used some code like this: void A() { typedef struct B B; struct

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.