There are a number of other question on SO that discuss how constants are declared and behave in Objective-C, you should look at the following:
Constants in Objective-C
Objective-C “const” question
Significance of const keyword positioning in variable declarations
To compare and contrast against C#, I would point out that const
in Obj-C is essentially the same as it is in the C language (Obj-C is a superset of C in fact). In Obj-C, constants are declared at the global scope and must be initialized to a value known at compile time. Objective-C does not support constants as class members. In C# constants are always members of a class (or struct) and must also be initialized using a value known at compile time. C# #define
does not allow a value to be associated with a defined symbol, rather it is used to allow conditional compilation paths to be chosen (using #if
and #else
), which is quite different.
With regard to using #define
to declare constants, I personally try to avoid this when possible. Values that are #defined
are simply substituted into code at compile time - and could be interpreted differently in different contexts. It's also possible to introduce name collisions which could result in redefinitions of a value unexpectedly. My suggestions is to use const
when you can and #define
only when you must.