DCMaxxx DCMaxxx - 1 year ago 162
iOS Question

Objective-C : #define vs extern const

I know this question has been asked before, but I can't seem to find information about it in Apple's documentation; maybe some of you guys did.

A lot of Objective-C code has cross-file constants in a

file, using
Others use the approach of a
with constants and
them in the

I understand the difference, both pros and cons, but does Apple state which one to use in iOS development?

Answer Source

Apple's recommendation is extern:

Define constants for strings used for such purposes as notification names and dictionary keys. By using string constants, you are ensuring that the compiler verifies the proper value is specified (that is, it performs spell checking).

Admittedly they are inconsistent about this sometimes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download