Closed diogot closed 9 years ago
Ah, re-reading the title so the const is referring to the pointer here, and not the NSString?
The const
is a bit tricky, it applies to the left side type unless it is not present, in this case applies to the right. Like const int x = 2
is the same as int const x = 2
.
The thing gets trickier when you get pointers, if you have a pointer to an object like NSString *x = @"a"
and want to make the object const you can do
const NSString *x = @"a"
or NSString const *x = @"a"
but if you want a constant pointer to a constant object const NSString * const x = @"a"
or NSString const * const x = @"a"
but since NSString
is immutable (and I'm not sure if it was a NSMutableString the former case makes it constant) you can drop the first const
:
NSString * const x = @"a";
You can take a look at Wikipedia article about const for more details.
Great, thanks @diogot :dancers:
Any reasoning for this?