Objective-C typedef enum in global constants file

房东的猫 提交于 2019-12-05 05:25:27

well, a constant and an enum serve different purposes (although there is some obvious overlap). so, just don't go too far from what people would expect, unless you have a really good reason to break that rule.

personally, i don't like the "global constants header" much, as you should usually associate those declarations with what they are used with. for example, Apple's frameworks typically declare the enums near the interfaces they relate to, and the notification names in the same header as the class.

other than that, you have declared things correctly.

if you use c++ or objc++, then you will want to fix that extern because the names may differ, and that can result in link errors.

something like this should do the trick:

#if defined(__cplusplus)
#define MONExternC extern "C"
#else
#define MONExternC extern
#endif

then you would declare BOOKS like so:

MONExternC int const BOOKS; 

one other note, and this may have been only for illustration in your example: those identifiers are very short, and can easily cause collisions with other identifiers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!