views:

680

answers:

3

I am getting a warning on this line in my header, but I am using the class variable in my implementation (in both class methods and instance methods):

#import <UIKit/UIKit.h>

static NSMutableArray *classVar; // Xcode warning: 'classVar' defined but not used

@interface MyViewController : UIViewController {
+3  A: 

You have placed the classVar outside the interface definition. This will make the compiler think you are declaring a global variable, and as this looks like it is a header file (.h) it will also be created in all files including this header file. I'd guess the warning comes when compiling a file other than MyViewController.m that includes this header file.

EDIT My suggestion is that you move the classVar into the .m file for MyViewController (miss-interpreted what you where after first)

epatel
+6  A: 

This variable is not a class/instance variable. Each time when the header file is included to .m file, the compiler creates a new static variable with scope limited to the file that includes this header. If you're trying to get a class level variable, move the declaration to the beginning of respective .m file.

gonzo
+3  A: 

A static variable has file scope. Since Xcode can't find the variable being used in that file, it sees an unused variable. If you actually want the variable to be accessible from your whole program, make that an extern variable declaration and define it in your implementation. If it's only meant to be used by that class, just move the static variable into your implementation file.

Chuck