views:

108

answers:

2

Hi,

Would you be able to help to delete the warning discussed below ?

I have one file example.h

In that I declared static const NSString *variable = @"cool";

Now, I have another file multiple.m. In this file I have a function Bool var2 = [object methodname:variable];

It means, I passed variable as parameter for this function, but I got warning like this:

variable is defined but not used

So,how to remove this warning?

please help me

+2  A: 

if example.h is imported in other files aside from multiple.m, then the compiler does the check in every file it is imported into, and reports when the variable is unused in that file.

if you want to get rid of the warnings, i would change that from a static const to a macro like so:

#define Variable @"cool"

GCC won't report on unused macros.

Kevlar
+1  A: 

What you should probably be doing is:

extern NSString * const variable;

in the header and then

NSString * const variable = @"cool";

in an implementation (.m) file.

(Also note where the const is; you can see this pattern in Apple's own headers as, e.g., FOUNDATION_EXPORT NSString * const NSFileTypeSocket where FOUNDATION_EXPORT is a #define for extern.)

Wevah