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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:52:08+00:00 2026-06-13T20:52:08+00:00

Im digging for ways to enum objc object such as NSString, I remember there

  • 0

Im digging for ways to enum objc object such as NSString, I remember there a new feature in a version of Xcode4+ which offering a new way to enum , but not clearly. Anyone know that?

  • 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-13T20:52:09+00:00Added an answer on June 13, 2026 at 8:52 pm

    OK, I answered myself. Guess I make a mistake.

    This is the new feature I mentioned above:

    typedef enum Language : NSUInteger{
         ObjectiveC,
         Java, 
         Ruby, 
         Python, 
        Erlang 
    }Language;
    

    It’s just a new syntax for enum in Xcode 4.4, but I’m so foolish to think we can exchange “NSUInteger” to “NSString”.

    So here is the way I found that works:

    http://longweekendmobile.com/2010/12/01/not-so-nasty-enums-in-objective-c/

    // Place this in your .h file, outside the @interface block
    typedef enum {
        JPG,
        PNG,
        GIF,
        PVR
    } kImageType;
    #define kImageTypeArray @"JPEG", @"PNG", @"GIF", @"PowerVR", nil
    
    ...
    
    // Place this in the .m file, inside the @implementation block
    // A method to convert an enum to string
    -(NSString*) imageTypeEnumToString:(kImageType)enumVal
    {
        NSArray *imageTypeArray = [[NSArray alloc] initWithObjects:kImageTypeArray];
        return [imageTypeArray objectAtIndex:enumVal];
    }
    
    // A method to retrieve the int value from the NSArray of NSStrings
    -(kImageType) imageTypeStringToEnum:(NSString*)strVal
    {
        NSArray *imageTypeArray = [[NSArray alloc] initWithObjects:kImageTypeArray];
        NSUInteger n = [imageTypeArray indexOfObject:strVal];
        if(n < 1) n = JPG;
        return (kImageType) n;
    }
    

    FYI. The original author of the second example code created a category for enum handling. Just the thing for adding to your very own NSArray class definition.

    @interface NSArray (EnumExtensions)
    
    - (NSString*) stringWithEnum: (NSUInteger) enumVal;
    - (NSUInteger) enumFromString: (NSString*) strVal default: (NSUInteger) def;
    - (NSUInteger) enumFromString: (NSString*) strVal;
    
    @end
    
    @implementation NSArray (EnumExtensions)
    
    - (NSString*) stringWithEnum: (NSUInteger) enumVal
    {
        return [self objectAtIndex:enumVal];
    }
    
    - (NSUInteger) enumFromString: (NSString*) strVal default: (NSUInteger) def
    {
        NSUInteger n = [self indexOfObject:strVal];
        if(n == NSNotFound) n = def;
        return n;
    }
    
    - (NSUInteger) enumFromString: (NSString*) strVal
    {
        return [self enumFromString:strVal default:0];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was recently digging about cookieless sessions, i came accross an article which says
I'm digging new scala reflection api and can't figure out why the following snippet
I'm digging F# and enjoying writing code in massively different ways. But I'm confused
While I was digging into OpenNTPD source code files, I noticed new keywords and
I have been digging into Play2!Scala documentation about possible ways of implementing authentication/authorization for
Was digging around my Rails applications and noticed that there are rails.rb files all
I did some digging and I understand that the array means there are multiple
I'm digging through Google's results for free (open source) Java diff libaries, and there
Today I was digging with TPL and found a new class Task.Now I just
I'm tired of digging through tons of tutorials/documentations which don't help me at all.

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.