本文介绍了Objective-C的/ C给枚举的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读的地方关于给枚举像这样的默认值:

I read somewhere about giving enums default values like so:

typedef enum  {
MarketNavigationTypeNone = 0,
MarketNavigationTypeHeirachy = 1,
MarketNavigationTypeMarket = 2
} MarketNavigationLevelType;

..但我不记得这样做的价值。后来再有人重新排序枚举 - - 如果我不给他们的默认值存在哪些风险?

.. but i can't remember the value of doing this. If i don't give them default values - and then someone later on reorders the enum - what are the risks?

如果我总是用枚举的名字,甚至不被他们整数值是指他们,有没有风险?

If i always use the enum name and don't even refer to them by their integer value, is there any risks?

唯一可能的问题,我能想到的是,如果我初始化从一个DB int值枚举 - 和枚举重新排序 - 然后应用程序将打破

The only possible problem i can think of is if i'm initialising an enum from an int value from a DB - and the enum is reordered - then the app would break.

推荐答案

在一般,如果这只是事项枚举暴露于某种外部API的,或者它是将要使用经由数据文件或其它装置交换数据。如果枚举只是每次你的应用程序中使用,在其他地方则实际值并不重要。

In general this only matters if the enum is exposed to some kind of external API or it is going to be used to exchange data via data files or other means. If the enum is only every used within your app and nowhere else then the actual values don't matter.

这篇关于Objective-C的/ C给枚举的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 02:21