"将'const NSString *'发送到类型为'NSString *'的废弃限定符的参数"警告

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?

转载于:https://stackoverflow.com/questions/6828831/sending-const-nsstring-to-parameter-of-type-nsstring-discards-qualifier

just to put all on one place which found on various post on stackoverflow and works for me , #define is bad because you cannot benefit from variable types, basically the compiler replaces all occurrence when compiles (import Constants.h whenever you need) :

//  Constants.h
#import <Foundation/Foundation.h>

@interface Constants : NSObject

extern NSString *APP_STATE_LOGGED_IN;
extern NSString *APP_STATE_LOGGED_OUT;
@end

// Constants.m
#import <Foundation/Foundation.h>
#import "Constants.h"

@implementation Constants

NSString *APP_STATE_LOGGED_IN  = @"APP_STATE_LOGGED_IN";
NSString *APP_STATE_LOGGED_OUT = @"APP_STATE_LOGGED_OUT";
@end

spare few minutes to read this. A goodread on pointers hell on constants and vice-versa.

http://c-faq.com/decl/spiral.anderson.html