Why is Xcode reporting a “specific but not used” warning for my class variable?

I get a warning in this line in my header, but I use a class variable in my implementation (both in class methods and in instance methods):

#import <UIKit/UIKit.h>

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

@interface MyViewController : UIViewController {
+5
source share
4 answers

This variable is not a class / instance variable. Each time a header file is included in the .m file, the compiler creates a new static variable with a scope limited by the file that includes this header. If you are trying to get a class level variable, move the declaration to the top of the corresponding .m file.

+14
source

A static . Xcode , , . , , . , .

+6

classVar . , , (.h), , . , , MyViewController.m, .

EDIT My suggestion is that you move classVar to a .m file for MyViewController (you misinterpret what you are after)

+3
source

Here is the right way to do this:

In .h

extern NSString *const DidAddRecordNotification;

In .m

NSString *const DidAddRecordNotification = @"DidAddRecordNotification";
0
source