Objective-c: NSString to enum

后端 未结 6 1642
滥情空心
滥情空心 2021-01-31 04:24

So, I\'ve got this definition:

typedef enum {
    red = 1,
    blue = 2,
    white = 3
} car_colors;

Then, I\'ve got a variable of type car_col

6条回答
  •  臣服心动
    2021-01-31 04:35

    There are a lot of great answers to this here: Converting between C enum and XML

    They are basically the same as Abizern's, but are a little cleaner and easier to work with if your app does this string-to-enum conversion a lot. There are solutions which keep the string and enum definitions together, and ways to make the conversions each a single, easy-to-read line of code.

提交回复
热议问题