I am thinking about that it would be a great idea for examining that the class type. In example I would like to do the following in my application prefix.pch file.
#if isViewController
#import "DeviceCompatibility.h"
#import "UIViewController+Utilities.h"
#endif
How could I do this.
Thanks for the ideas and your time
This won't work. The point of a pch file is that it is a "Pre Compiled Header" file. It's compiled once and then that is used in every other file.
What you are asking for would require that it not be pre-compiled since it would need to be evaluated for each file. What you want is what regular, non-pch files are for.
Related
I'm using C++Builder. I want to include a header file that is located in a separate folder from my project.
I tried to add the folder to the search path, and include the file in my project:
#include "GXWARE32\Include\gxutils.h"
but when I compile I have some errors in the file included
So, I tried to add all subfolders to the search path, and it works with a small folder but not with a big one.
According to the error log, maybe you missed some header file that gxutils.h relies on.
Without code, we can only guess... some libs need a specific #include order... some libs have hard-coded relative paths and by moving them you broke that... Some libs also need configuration macros defined before #include.
From the errors, you have #include'd some file more than once (and it's not protected by a header guard, like #pragma once or #ifndef file_id #define file_id ... #endif macros) and you are missing a previous #include for some datatype used.
Open the gxutils.h file and look around line 143 for the missing datatype. In the IDE, during compilation the cursor usually stops on the stuff directly. Then just search the files in your lib for the datatype, so you know what file to #include before...
All of these might happen sometimes if you include the wrong file... some libs need to include cpp instead of h...
Adding search paths will not do anything as the compiler is not complaining about files not found...
I have an iOS project-ProjectX (not created by me) which is able to access declaration from a .h file without using #include "someHeader.h".
In ProjectX, I could just create an empty File and refer to a declaration in "someHeader.h", which I find perplexing. Example:
#import <Foundation/Foundation.h>
#implementation Empty:NSObject
SOME_TYPE_FROM_SOME_HEADER_H x;
#end
and the compiler automatically knows where the definition is?!
I have since tried to create an identical project, duplicating all the project settings, adding static libraries/files, etc. but to no avail.
Any ideas on what I might have missed out or what do I need to configure in the project to achieve this?
As mentioned by Rishab, I was missing a precompiled header (.pch) file. In the project, a pch imported a static library which contained the header file. Therefore, I was able to call the definitions directly.
I wrote my own macros to output detail message in development environment
#ifdef DEBUG
#define GCLog(fmt, ...) NSLog((fmt), ##__VA_ARGS__);
#else
#define GCLog(...);
I don't want to import this in every file, and I know the shortcoming of PCH file.
So what can I do with this?
You've got four options:
Import some file containing that macro in every file you want to use
it in
Put it in the PCH which is automatically imported for you
Put it in a file and import that file in the PCH
Include that macro in every file you want to use it (generally a bad plan)
Personally when I was writing Objective-C, I would go with option 2 when I wanted something available in every file.
I don't know how to describe this question clearly,I can't speak English very well.
I'm creating a CocoaPods Spec, I got these folders and files in my project:
MySDK/*.(h,m)
MySDK/AdvertisementSDKS/Millennial/*.(h,m)
MySDK/AdvertisementSDKS/Millennial/SDK/MillennialMedia.framework
and Podspec's source_files looks like
s.source_files = "*.{h,m}", "AdvertisementSDKS/**/*.{h,m}"
also include framework
s.vendored_frameworks = 'AdvertisementSDKS/Millennial/SDK/MillennialMedia.framework
in Millennial folder there is a .m file that imports:
#import <MillennialMedia/MMInterstitial.h>
When I try compile, Error occurs, Because compiler cant find the path of MillennialMedia/MMInterstitial.h
The correct import way is
#import <MMInterstitial.h>
Are there any settings I missed, that I can set to keep the original #include path?
Because there are lots of other same issue, I have to modify it one by one...
Thank you!
OK, I'll answer my own question:
I missed some settings of Podspec, Just simply add
spec.header_dir = './'
(The directory path depends on your project)
To your podspec, Then, It'll keep the original path works
Don't need to modify the header path! Woohoo!
I have a Global.h that looks like
#define NUMBERX 21
In AppDelegate.h I include the Global.h file. In the AppDelegate.m I include the AppDelegate.h file. But in the AppDelegate.m I can't access the NUMBERX variable.
ERROR: Use of undeclared indentifier 'NUMBERX'.
If I define NUMBERX in AppDelegate.h than it works, but I want include only the header file (Global.h) in all other header files where I want to use the NUMBERX variable.
How can I solve that?
If you're using objective-c standard #import to include your header file, try replacing it with a "c" #include.
This should be fine, assuming you're not #undefing it before you're using it. Are you using the symbol before you include AppDelegate.h in the AppDelegate.m file? Are you using include guards that might prohibit it's inclusion?
You have to include your Global.h file in AppDelegate.m file.
Could you not use int const NUMBERX then you will get code completion and compiler checking.
Apple has some pretty good guidelines on defining constants and naming them here
Apple Coding Guidelines - Constants