[Solved] sending const NSString * to parameter of type NSString * discards qualifiers

For example, I wrote

const NSString* firstString = @”xxx”;

NSString* secondString = @”yyy”;

[secondString isEqualToString:firstString];

 

The sending ‘const nsstring *’ to parameter of type ‘nsstring *’ discards qualifiers warning appears.

 

Solution:

Set const nsstring * firststring = @ “XXX”;

Change to nsstring * const firststring = @ “XXX”;

 

Explanation: the former means that the pointer itself is not modifiable, while the latter means that the content pointed to by the pointer is not modifiable. Both functions are to make the firststring only readable and not writable.


Read More: