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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:59:12+00:00 2026-05-18T06:59:12+00:00

i have an enumeration say gender, now i want to associate it to string

  • 0

i have an enumeration say gender, now i want to associate it to string values to use in the view inside a picker view. It’s cocoa-touch framework and objective-c as language.
So i don’t know of a way to set the data source of the picker view as the enumeration, as could have been done in other frameworks. So i’ve been told i have to make array of enum values. and then i tried to add thos into an NSMutableDictionary with their respective string values.
So i ended up with

NSArray* genderKeys = [NSArray arrayWithObjects:@"Male",@"Female",nil] ;
NSArray* genderValues = [NSArray arrayWithObjects:[NSNumber numberWithInt:male],[NSNumber numberWithInt:female],nil];

for(int i =0;i<[genderKeys count];i++)
    [_genderDictionary setValue:[genderValues objectAtIndex:i] forKey:[genderKeys objectAtIndex:i]];

and it’s not working saying it’s not a valid key, and i’ve read the key-coding article and i know now what’s key and whats keypath, but still how can i solve that. It’s ruining my life, Please help.

Sorry guys, i was using NSDictionary for _genderDictionary.But i had in my mind that it was nsmutable. Thank you all.

  • 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-18T06:59:12+00:00Added an answer on May 18, 2026 at 6:59 am

    That works for me. Running this (your code, with the first line added so it would compile) seems to work fine.

    NSMutableDictionary *_genderDictionary = [NSMutableDictionary dictionary];
    NSArray* genderKeys = [NSArray arrayWithObjects:@"Male",@"Female",nil] ;
    NSArray* genderValues = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:2],nil];
    
    for(int i =0;i<[genderKeys count];i++)
        [_genderDictionary setValue:[genderValues objectAtIndex:i] forKey:[genderKeys objectAtIndex:i]];
    

    NSLog()-ing _genderDictionary outputs this

    {
        Female = 2;
        Male = 1;
    }
    

    edit: re-reading your question, makes me think what you are looking for is the delegate methods of UIPickerView… implementing –pickerView:titleForRow:forComponent: is where you set the text that appears in the picker. If you have an NSArray of genders, you would do something like return [_genderArray objectAtIndex:row]; That way you don’t need to fuss around with a dictionary and keys.

    edit 2: a picker’s datasource can’t be an NSArray or NSDictionary directly. It has to be an object that implements UIPickerView’s datasource/delegate protocol (which I suppose you could do with a subclass of NSArray, but that’d be cah-ray-zay!).

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

Sidebar

Related Questions

I have to say I don't understand Scala enumeration classes. I can copy-paste the
Let's say you have an enumeration type with 50+ entries for its value. There
Let's say I have a sequence. IEnumerable<int> sequence = GetSequenceFromExpensiveSource(); // sequence now contains:
Is it possible to use an enumeration in the following circumstance: Let’s say you
Let's say you have a view-model that controls a media player. It has to
I have a HashTable like HashTable<String, String> table=new HashTable<String, String>(); table.put(1,ABC); .......continues Now with
Possible Duplicate: C++: Print out enum value as text Say I have an enumeration:
Let's say I have an enumeration. enum class ShapeName : char {TRIANGLE,CIRCLE,SQUARE}; and later
I have enumeration in JAVA code ERequestTypes my enumeration contains more then 20 elements,
I have this enumeration: public enum Translation { English=1, Russian, French, German } I

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.