Possible Duplicate:
“static const” vs “#define” in C
In Objective-C what is the difference between the following two lines:
#define myInteger 5
static const NSInteger myInteger = 5;
Assume they're in MyClass.m above the implementation directive.
Possible Duplicate:
“static const” vs “#define” in C
In Objective-C what is the difference between the following two lines:
#define myInteger 5
static const NSInteger myInteger = 5;
Assume they're in MyClass.m above the implementation directive.
 
    
     
    
    #define myInteger 5
is a preprocessor macro. The preprocessor will replace every occurrence of myInteger with 5 before the compiler is started. It's not a variable, it's just sort of an automatic find-and-replace mechanism.
static const NSInteger myInteger = 5;
This is a "real" variable that is constant (can't be changed after declaration). Static means that it will be a shared variable across multiple calls to that block.
 
    
    When using #define the identifier gets replaced by the specified value by the compiler, before the code is turned into binary. This means that the compiler makes the substitution when you compile the application.
When you use const and the application runs, memory is allocated for the constant and the value gets replaced when the applicaton is ran.
Please refer this link:- Difference between static const and #define
 
    
    There are differences:
Define is textual substitution:
Static const is a variable in memory
 
    
    #define myInteger 5 is a macro that declares a constant. 
So wherever you use myInteger macro it gets replaced with 5 by the preprocessor engine. 
const NSInteger myInteger = 5; declares a variable myInteger that holds the value 5. 
But their usage is the same, that is they are constants that can be used to prevent hard coding.
