static const NSInteger kHotWordNumber = 6;
1)static應該放到開頭 (c語言的要求, 習俗),不放到最前可能會有編譯器警告
2)static標示作用域
3)const標示只讀
const int*是不同的
static const int *kConstInt =0;? //*kConstInt=1;是不行的? int*的指針kConstInt的內容是只讀的,但是kConstInt是可以指向別處的,kConstInt指向的地方的內容變成只讀的,所以kConstInt= 另一個int*b是可以的。
static int* const kConstInt =0;? //*kConstInt=1;是可以的, kConstInt本身變成只讀的,不可以修改。
const NSString * vs NSString *const
static const NSString *HotCellReuseId = @"HotCollectionViewCell"; //(可以修改HotCellReuseId的值)
static NSString *const HotCellReuseId = @"HotCollectionViewCell"; //(不允許修改HotCellReuseId的值)
在執行HotCellReuseId=@"1";后,第一種形式不會報錯,第二種形式會保錯。
const int是不區分前后的
static const int kConstInt = 0;
static int const kConstInt = 0;
兩者是一樣的,在xcode上都被識別成const int,不允許修改kConstInt的值。
【 Cannot assign to variable 'kConstInt' with const-qualified type 'const int' 】