I have Constants NSString, that I want to call like:
[newString isEqualToString:CONSTANT_STRING];
Any wrong code here?
I got this warning:
sending ‘const NSString *’ to parameter of type ‘NSString *’ discards qualifiers
How should these be declared?
You should declare your constant string as follows:
instead of:
The former is a constant pointer to an
NSStringobject, while the latter is a pointer to a constantNSStringobject.Using a
NSString * constprevents you from reassigning kSomeConstantString to point to a differentNSStringobject.The method
isEqualToString:expects an argument of typeNSString *. If you pass a pointer to a constant string (const NSString *), you are passing something different than it expects.Besides,
NSStringobjects are already immutable, so making themconst NSStringis meaningless.