How add new enums in typedef enum in Objective C?-Collection of common programming errors


  • Johannes Rudolph

    I need help, i have typedef enum:

    typedef enum category
    {
        All, 
        category1,
        category2,
        category3,
        category4,
    } category;
    

    Can I add new enums in category, for example:

    typedef enum category
    {
        All, 
        category1,
        category2,
        category3,
        category4,
        category5,
        category6,
        category7,
    } category;
    

  • jrturton

    Yes, you can. Just add them. You aren’t changing the values of the existing ones or changing the order, so any storage of these values in your previous version will be unaffected.

    If you want to update the list at runtime, as suggested in your comments, then this isn’t possible and an enum is the wrong structure to be using. An enum isn’t much more than a fancy list of constants. You would need a different solution.