How to access header file declaration without #include - ios

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.

Related

C++ Builder include header file from other folder

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...

Xcode template to import file by file path

I have a Xcode template file like so:
#import "___FILEBASENAME___.h"
#implementation ___FILEBASENAMEASIDENTIFIER___
#end
This will create an example file like so:
#import "ExampleFile.h"
#implementation ExampleFile
#end
However due to some complexity in our build system, I need to import files by their file path.
For example, if I was creating ExampleFile.m inside of Path/To/ folder. Then my desired output would be:
// Desired template output
#import "Path/To/ExampleFile.h"
I tried looking through some Apple example templates, but didn't seem to find a way to make it work.
I also stumpled upon ___DIRECTORY___ referenced here, but it doesn't seem to work for me when I attempted to use it.
Does anyone know if there is a way to accomplish this?
Try enabling "Use custom working directory" option, it will let you choose the base directory.
How to enable this is answered in the following question.
Xcode: How to set current working directory to a relative path for an executable?
Hope this helps

Expected identifier for every occurance of "(Class)class" in LARSAdController

I'm currently trying to add LARSAdController to my iOS project with no success.
As soon as i import the files via #import "LARSAdController.h" in my AppDelegate.h the build process fails and on every occurance of (Class)class in LARSAdController.h i get the cryptic error "Expected identifier". BTW I'm using cocoapods.
Example:
- (void)registerAdClass:(Class)class;
which seems fine to me...
If i create a blank project and import the files they compile, so the problem must be in some relation to my code. Anyone got an idea what may cause this?
Thanks for any help in advance!
class is a reserved word in C++, so I would imagine that some of your project uses Objective-C++.
To solve this, use #import LARSAdController.h in Objective-C implementation files only, and remove its use from header files. You can use #class to forward-declare any occurrences of whatever classes are defined in LARSAdController.h in header files (this is best-practise anyway).
If you need to use LARSAdController from an Objective-C++ class then this is more complicated and you will need to use an Objective-C proxy object or modify their header files (which isn't ideal).

Examine filetype in prefix.pch

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.

#define in header files in Objective-C

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

Resources