Someday, I found one issue in the Xcode. I used one macro for anywhere I want, the problem is I was't imported one .h file where the macro defined, in fact I can use this macro normally. Can somebody help me?
Asked
Active
Viewed 609 times
0
-
What is the problem you try to solve? Circular imports? Then use [`@class`](http://stackoverflow.com/questions/5191487/objective-c-forward-class-declaration). Or do you want do save typing work? Then look for the [precompiled header](http://stackoverflow.com/questions/6707590/is-there-a-place-to-put-a-category-import-statement-so-all-classes-see-it/6707627#6707627) – Matthias Bauch Oct 11 '13 at 07:14
2 Answers
0
Import to the precompiled header file *.pch
in your project, that way it will be imported to any implementation file automatically. See here
-
Though it's best not to mess with the .pch file unless you need that macro in 90% of your controllers). – Lord Zsolt Nov 14 '13 at 13:00
0
defining any macro inside <your project>.pch
will work for entire app automatically. You can find this auto-generated file inside Supporting Files
in your project directory.
In .pch
file you should declare all those constants and and macros you are using throughout the app (not recommended if you are not using these variables in most of the viewcontrollers
) and in most of the viewControllers
for example:
// frameworks
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
// a category
#import "UIColor+custom.h"
// a class
#import "aClass.h"
// a macro
#define kAppFont @"TrebuchetMS"
// a global object
NSInteger myInteger;
// a macro with case
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

Vaibhav Saran
- 12,848
- 3
- 65
- 75