Const
const简介
: Commonly used string constants, usually pumping macro, but Apple does not recommend us to smoke macro, we recommend using const constants.
编译时刻
: Macros are precompiled (processed before compilation), and const is the compile phase.
编译检查
: Macros do not check, do not report compilation errors, just replace, const will compile the check, will report a compilation error.
宏的好处
: macros can define some functions, methods. Const cannot.
宏的坏处
: With a large number of macros, it is easy to compile for a long time and need to be replaced each time.
Macros define constants, constants are placed in constant areas, and only one copy of memory is generated.
Const: Const is a left-associative type modifier that, along with its left type modifier, is a type modifier that indicates that the type is read-only.
简言之:沿着*号划一条线,如果const位于*的左侧,则const就是用来修饰指针所指向的变量,即指针指向为常量;如果const位于*的右侧,const就是修饰指针本身,即指针本身是常量。
static const NSString *PERSONA1 = @ "A1";//cannot provide outside access after being modified with static
The *PERSONA1 is constant and cannot be modified, but the personA1 is mutable and can point to the new memory address, and when PersonA1 is assigned, personA1 points to the new memory, and the value of the read is changed;
static NSString *const personA2 = @ "A2";//string constant personA2 cannot be re-assigned;
Https://www.jianshu.com/p/2fd58ed2cf55
https://jatstar.cn/2016/01/10/const-static-extern/
Https://www.jianshu.com/p/b86278d322f5
Summary of Const,static,extern usage in IOS development