In swift, Prefix.pch file is not provided. In my project, I want to declare some macros globally and use through out application.
Can anyone give me suggestion how to do it, Where to declare?
Is there any other file replaced by Prefix.pch file in swift?
Prefix Header(GCC_PREFIX_HEADER) - path to .pch . Adds all content from .pch to all source files.
In computer programming, a precompiled header (PCH) is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler.
Even in Obj-C, using Macros for constants and expressions is something you shouldn't do. Taking examples from your comments:
#define NAVIGATIONBAR_COLOR @"5B79B1"
It would be better as a category method on UIColor
, for example
+ (UIColor *) navigationBarColor {
return [UIColor colorWith...];
}
The isPad
macro should be either a plain function
BOOL isIPad() {
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}
or again a category method, e.g. on UIDevice
[UIDevice isIPad]
defined as
+ (BOOL)isIPad {
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}
The precompiled headers were never meant to share macros to all of your code. They were made to include framework headers there to speed up the compilation process. With the introduction of modules last year and now with the possibility to create custom modules, you don't need precompiled headers any more.
In Swift the situation is the same - there are no headers and no macros so there is also no precompiled header. Use extensions, global constants or singletons instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With