import modulname-Swift.h is working in .m but not in .h files - objective-c

I try to mix swift and Obj-c in my project.
I made a couple of Swift classes (and protocolls).
If I put #import "ModuleName-Swift.h" to an .m file, it's working properly, but if i try to put it to a .h file, it says "ModuleName-Swift.h" file not found.
What could be the problem?

import <ModuleName-Swift.h>
try using angle brackets instead.

Related

Importing modulename-Swift.h file to ObjC .h file

Is it possible to import the modulename-Swift.h file to another .h file, so that the test target also would compile?
Currently, I was importing the modulename-Swift.h in the one of the headers of the app's target, however, the test target was not able to compile.
When I moved the import statement to the .m file instead, I was able to compile both, the app and the tests.
However, I have to resort to a forward protocol declaration in order to resolve this issue - the modulename-Swift.h file contains a protocol.
So, the question is whether I can import that file in .h file at all?
No, you can't import modulename-Swift.h in a .h file. You'll need to create forward declarations (adding #protocol Something; to your .h) and import the Swift module in the .m file.
Another way to work around this is to declare the protocol conformance in a category in the .m file. More details can be found in this StackOverflow answer:
https://stackoverflow.com/a/27626493/3208043

Cannot import Objective-C code into Swift file

I would like to import an objective c code from TwitterAuthHelper.h file into my swift code.
After that i added the header file to my project, i created the Bridging Header file that i defined " #import "TwitterAuthHelper.h" " inside of it.
The Bridging file that i added ' #import "TwitterAuthHelper.h" '
However, when i wanted to use TwitterAuthHelper(firebaseRef: .... inside that swift file, it says "use of unresolved identifier 'TwitterAuthHelper'", even though i defined the import of header file inside of the Bridging Header file.
The Swift file that i would like to import the objective C code into
Any help would be greatly appreciated.
I have had some experience with this you should make sure that you named your bringing-header file correctly. You also my clean your build and then build it again.
i'm fix this
insert #import <Accounts/Accounts.h>
in file TwitterAuthHelper.h and clean the project.

Importing .mm file to another .mm file on xcode

I am getting error when trying to import .mm file to another one.
Its build like that :
first class FailedMenuLayer is .mm and have in its .h :
#import "gameScene.h"
second class gameScene is .mm, and have in its .h :
#import "FailedMenuLayer.h"
FailedMenuLayer *menuGO; //here i get the error: unknown type FailedMenuLayer .
why is that ?
It looks like an import cycle.
One way to fix it is to move the "gameScene.h" import to the .mm file. It's actually a good practice to keep the imports in the .h file limited only to what you actually need in the header and keep everything else in the .mm file.
If you need the import in the header try using #class instead of #import;
#class gameScene;
Don't forget to import gameScene.h in the .mm file also.
you are not importing ".mm" file, you are importing it's header.
Check your build phases> compile sources for your .mm file to be listed there. That might be your issue

Where to #import on Objective-C

My project has been increasing in size and I'm a little confused about where should I #import header files.
There are 3 main locations where I can import headers:
The .pch file (prefix)
The .h file (header)
the .m file (implementation)
I don't care if the compiler takes more time to compile the files, all I care is that the end product is as fast as possible and uses the least amount of memory.
So, my questions are:
If most files need a specific header, is it ok to add it to the .pch file, or is it more efficient to add it to just the required files?
Should imports be done in the .h or .m file? I know I must add it to the .h file if i'm going to declare it there, but if I don't need to declare it in the .h file is there a problem of leaving the import there?
No, it is not ok to include it into the .pch file. This file is precompiled to every module in the project. Read about it here.
Read this question and answer.
Put your imports in your .m whenever you can. If you are using a class in your .h use #class to forward the declaration, then #import in your .m. The only time you should import in your .h are protocols that you implement or superclasses.

including a class from another folder in Xcode Objective-C

I have two folders under my project: WebServices and classes.
How would I include DriverServiceService (in WebServices), in XMLViewController.h (in classes)?
I used the following with no luck:
#import <../WebServices/DriverServiceService>
#import <"WebServices/DriverServiceService">
#import <DriverServiceService>
try to import with without '<' and '>' and give the path as ../ if class is not in the root.
#import "../WebServices/DriverServiceService" worked for me.
If you want to use classes that are in a folder other than the root of your project, you can drag in or "add existing files" to your project. Make sure the "copy" option is unchecked. Now your project references those files in the project while they remain in their original location.
In some versions of Xcode, auto completion might not work. Let's assume that the classes you are going to import are named "MyClass.h" and "MyClass.m"
To import, you simply give the filename like following:
#import "MyClass.h"
oops, nevermind
just learnt to use ""