#define in header files in Objective-C

I have Global.h that looks like

  #define NUMBERX 21

In AppDelegate.h, I include the Global.h file. In AppDelegate.m, I include the file AppDelegate.h. But in AppDelegate.m, I cannot access the NUMBERX variable.

  ERROR: Use of undeclared indentifier 'NUMBERX'.

If I define NUMBERX in AppDelegate.h, how does it work, but I want to include only the header file (Global.h) in all other header files where I want to use the NUMBERX variable.

How can i solve this?

+4
source share
4 answers

If you use objective-c standard #import to include your header file, try replacing it with "c" #include .

+1
source

This should be good if you do not #undef it before using it. Do you use a character before including AppDelegate.h in the AppDelegate.m file? Do you use include defenders who may prohibit its inclusion?

+1
source

You must include the Global.h file in the AppDelegate.m file.

0
source

Could you use int const NUMBERX , then you will get code completion and compiler verification.

Apple has pretty good guidelines for defining constants and their names . Apple Coding Rules - Constants

0
source

All Articles