imported xcode generated swift header not found in .pch file - ios

I have recently added a Swift file to my Objective-C only project. Xcode created the necessary header files, including the Objective-C Generated Interface Header. Everything works fine if I #import this header file "myProject-Swift.h" to the .m file where I am accessing the Swift class I have added.
However I will want to eventually use this Swift class throughout my project, and to avoid importing it every single time, I wanted to add this myProject-Swift.h import file to my .pch prefix file.
However when I try to build my app after having added this, I get a 'myProject-Swift.h' file not found error and the build fails.
Does this mean it is not possible to import this myProject-Swift.h in a .pch file?
Is it really only possible to do it in each .m file individually?

Related

Xcode8 can not import vendor framework header files?

After I updated my Xcode toXcode 8.
I found out that if I import vendor framework header files in .pch file. there will be a error. 'xxx' .h file not Found
Such as:
I want to import a framework named Umeng's header file.
So I write the codes below to my XXX-prefix.pch
#import <UMMobClick/MobClick.h>
But Error UMMobClick/MobClick.h file not found appeared.
Any constriction of Xcode that prohibit importing vendor framework header files in .pch file?
I had a similar problem with a legacy Xcode project that used a .pch file -- the file was being ignored.
The fix was in build settings, where the original path to this file assumed it began at the project root:
SharkAlert/SharkAlert-Prefix.pch
Xcode 8 apparently requires an explicit reference to the starting point
$(SRCROOT)/SharkAlert/SharkAlert-Prefix.pch
Now the project builds as expected.
If this file you are used to bridge OC and Swift,now you should creat a new .header file and Move All Header file Name inside file
I had a similar issue. Changing #import <Framework/Framework.h> to #import Framework; fixed it for me.

Swift header stop compiled

I have very strange error.
I am using a Swift class in Objective-c. I have Bridging-Header.h created, import MyProject-Swift.h in my file, and all WORKS perfectly!
So, now i meet a very strange error. I made no changes in projects settings, no change in swift files or something else. When i build now the project, i receive this error MyProject-Swift.h file not found suddenly.
I checked all Settings in Project:
Defines Modules is set to YES
Objective-c generated interface header is set to MyProject-Swift.h
MyProject name is not contains space!
And isn't work for any file: .h or .m
EDIT:
Is weird because i can se swift class in my objective-c file, and i can use it, but i take always the only error: MyProject-Swift.h file not found

ModuleName-Swift.h file not found inside of CocoaPod Project

Issue
I have a CocoaPod project created using pod lib create. There are some Objective-C classes that can be used inside the example project — I am now trying to add a NSObject subclass written in Swift.
The Swift class was created and the bridging header was added to the classes directory.
I try to import the Swift bridging header into the .m file of another class inside the pod project:
#import "PROFlyoutViewController-Swift.h"
When I compile I get 'ModuleName-Swift.h' file not found
When the import statement is:
#import <ModuleName/ModuleName-Swift.h>
or
#import "ModuleName/ModuleName-Swift.h"
it compiles and is usable!
But...
I return to the file, indexing runs (I assume) and all of a sudden I get:
ModuleName/ModuleName-Swift.h file not found.
Autocomplete is broken on that file and any use of that class shows a warning.
Question
When using trying to use a Swift Bridging header within the files of a pod project, how should it be imported? What do I need to do in order to get autocomplete working and compilable?
Try using #import PROFlyoutViewController; instead as it is an external module.
See the below Example of my TableDemo project
To import Swift code into Objective-C from the same target
Import the Swift code from that target into any Objective-C .m file within that target using this syntax and substituting the appropriate name:
#import "TableDemo-Swift.h"
The Swift files in your target will be visible in Objective-C .m files containing this import statement. For information on using Swift from Objective-C code, see Using Swift from Objective-C.

Mixing Swift and Objective-C : "ProjectName-Swift.h" file not found

I'm working on an iOS project that contains Swift and Objective-C Classes.
To instantiate an object described in Objective-C, I've understand that I needed to have a Bridging-Header file that contains all the imports of the headers I will have to use on my Swift classes. And it works great on my project.
I made all classes I needed, I subclassed Objective-C classes in Swift, everything is OK.
My problem is when it comes to do the opposite: instantiate a swift object in an Objective-C file. So I read that I need to have those options:
Define Modules as Yes
add the line #import "<#YourProjectName#>-Swift.h" on the *.m file I'm working on.
And that is what I did:
I changed all the values on the Build Settings that needed to be changed. I added the import line, I even tried to create the header file, but I still have the "<#YourProjectName#>-Swift.h" file not found error.
Of course, I replaced the YourProjectName by the actual module name, the one I found under Product Module Name in Packaging section on Build Settings. Also, there is no spaces in the Project Name.
Did I forgot a step?
Make sure you are importing the -Swift.h file from a .m Objective-C file and not a .h header file. The docs only talk about importing from .m:
... import the Xcode-generated header file for your Swift code into any Objective-C .m file you want to use your Swift code from.
The -Swift.h file is generated during the build and I've found that importing it from a .h file always fails, even when I know the file exists. Since it's generated by the build, I'm guessing it's cleaned out when the compiler is sifting through the headers and regenerated once the .swift files are compiled.

Swift Bridging Header and visibility of Obj-C class

I've aded bridging header, specified in build settings the full path to it, bridging header was created automatically. After this, i've included my obj-c header files in it. But every attempt of calling constructor of object fails : "Use of undeclared identifier".
The list of things i've done :
Created .m file and Xcode proposed to create bridging header
Added obj-c files to project and imported them in header
In build setting provided the FULL path to bridging header file
Used Obj-C type in code... But it doesn't builds.
Then, i provided not the full path to the header, but the path from the folder in which project is - no result.
I double-checked all the steps according to apple documentation, but no result.
Why? Any help would be appreciated.
Follow these steps:
Create a Swift project
Add a test class as Cocoa Class instead of .m and .h separately. Xcode prompt add bridging header.
Import test class header in bridging header, which you already did. Should have no issue instantiate test class in Swift.
Copy BL_KeyChainWrapper .m and .h to project directory in finder.
Drag BL_KeyChainWrapper files to project and make sure Add to Targets.
Import BL_KeyChainWrapper header in bridging header.
Instantiate BL_KeyChainWrapper class in Swift.
If followed the above steps, and still have the error. It is probably that you didn't declare a class named BL_KeyChainWrapper in BL_KeyChainWrapper.h. Make sure in your BL_KeyChainWrapper.h, you have code like following:
#interface BL_KeyChainWrapper : BaseClass
Well, after creating a test project with bridging header, I found out the following:
I added .m file, Xcode proposed me to create bridging header.
I added .h file, named it as class and created Obj-C class in this way.
AND:
In build settings - code generation section looks like this:
Bridging file located at the following path:
ProjName / BridgHeader.h
At the same level as .xcodeproj file exists.
BUT:
When I added already created Obj-C class to project and added header import in bridging header, I couldn't use it:
So, I guess, Xcode 6 beta 2 cannot add existing files to swift project. Did anyone face this trouble? Cause I don't want to paste all existing libraries, that I was developing for 5 years to created files.
P.S:
Bridging header:

Resources