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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:41:28+00:00 2026-06-03T02:41:28+00:00

Is there a way to assign values to enums during runtime in objective c?

  • 0

Is there a way to assign values to enums during runtime in objective c?
I have several enums and want each of the enum to have certain value.
The values could be read from a xml file. Is there a way to do this?

  • 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-03T02:41:30+00:00Added an answer on June 3, 2026 at 2:41 am

    Unfortunatley, @Binyamin is correct, you cannot do this with an enum. For this reason, I usually do the following in my projects:

    // in .h
    typedef int MyEnum;
    
    struct {
        MyEnum value1;
        MyEnum value2;
        MyEnum value3;
    } MyEnumValues;
    
    // in .m
    __attribute__((constructor))
    static void initMyEnum()
    {
        MyEnumValues.value1 = 10;
        MyEnumValues.value2 = 75;
        MyEnumValues.value3 = 46;
    }
    

    This also has the advantage of being able to iterate through the values, which is not possible with a normal enum:

    int count = sizeof(MyEnumValues) / sizeof(MyEnum);
    MyEnum *values = (MyEnum *) &MyEnumValues;
    
    for (int i = 0; i < count; i++)
    {
        printf("Value %i is: %i\n", i, values[i]);
    }
    

    All in all, this is my preferred way to do enums in C.

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

Sidebar

Related Questions

Is there a way to assign 2 variable values to a value in a
Is there a way to to evaluate a boolean expression and assign its value
Is there a way in MySQL table to assign a default when a value
I have a menu which has an item for each value in an enum.
Is there a way to assign a default values to arrays in javascript? ex:
Is there a way to assign the values of a list to a list
Is there a way in Objective-C to set a property value of a class
Is there any other way to assign values to template class members in constructors,
Is there a way to assign values in a JavaScript array in the way
Is there a way to assign a binary value to a VB variable? 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.