objective-c Bridging header not found in swift compiler-code generation - ios

I am doing an ios app in swift 3. And I want to add ARKitwhich is available in objective-c. I dragged all objective-c files into my project then it asked to create bridging header. So I let it to create. And I imported all objective-c.h files inside that like this.
But when I try to build its showing 22 number of issues like UIViewcannot identify etc..
Then I tried to add the bridging headerpath to build settings under swift compiler - code generation. But I dont see objective-c Bridging headersection under that.
Please help me. What can I do to add these objective-c files into my swift 3 project successfully.
Thanks

The Objective-C bridging header setting can be found under Swift Compiler - General under Build Settings.
But I like to add the bridging header by having Xcode generate it for me. I add a junk Objective-C class by File > New > File... and it will ask me if I want to add a bridging header to my project.
If you do that, you'll only need to move whatever you have in your bridging header now to that one and delete the header you have now. The header will be set properly in the project's settings.

Make sure your build setting is selected as "All" and "Combined" look at below link
Swift Compiler - General is missing in Xcode 9.1

Related

How do I create an Objective-C bridging header?

I'm following this guide on adding OneSignal to React Native, and there is one section where is says:
Open NotificationService.m or NotificationService.swift and replace the whole file contents with the code below:
<provides code to add>
If you are using Swift, make sure to create a separate Objective-C Bridging Header for your OneSignalNotificationExtensionService and add the following import:
#import "RCTOneSignalExtensionService.h"
Then you need to tell your Xcode project settings what your bridging header is named, like this.
I added the code they provided to NotificationService.swift because that's the only one of the two files that exists in my project. So I assume I'm "using swift" as they put it. The problem is that when they say to create a separate Objective-C Bridging Header, I don't know how to do that. All I've been able to find online is that when you import Objective-C code into your swift project, Xcode should automatically prompt you to create a bridging header. Xcode hasn't done that for me.
Does anyone know how I can create an Objective-C bridging header?
You have to create a new objective c class:
then
then you name it and specify as objective-c class at language
then you select your directory and hit create. At this point xcode is going to ask you whether or not you want to create bridging header. Yep do it.
And at the end it should look more or less like this at your project.
hope that helps you.

"Objective-C Bridging Header" entry in Build Settings does not appear in Xcode 8.3

I need to add some Objective-C files of a library to my project, and I created the MyProject-Bridging-Header.h file myself. But now I'm not able to set its path because in the project's Build Settings I don't find the Objective-C Bridging Header entry.
Is somebody else experiencing the same? How could I solve this?
In Build Setting choose "all" instead of "basic"
Usually when you had an Objective-C/Swift project and have added new Swift/Objective-C class file Xcode asks whether you want to create Bridging Header or not.
If the option to create Bridging Header automatically f.e. has been denied there`s still an option to create it manually.
Since you have already created YourProject-Bridging-Header.h header file all you need to set the path to it in your project Build Settings.
To set the path to your Bridging Header file you need to navigate to your project Build Setting where look for Swift Compiler – General section like the Hoa mentioned above. It is located between "Swift Compiler - Custom Flags" and "Swift Compiler - Search Paths" ones at the same page with all "Swift Compiler" sections.
There you can see Objective-C Bridging Header which you can click and set the path to your YourProject-Bridging-Header.h Bridging Header file like YourProjectName/YourProject-Bridging-Header.h.
Now you can open up your YourProject-Bridging-Header.h and put Objective-C/Swift classes using the #import statement into it.
Thanks to http://www.learnswiftonline.com/getting-started/adding-swift-bridging-header/
And Objective-C Bridging Header not getting created with Xcode 8

How to solve Bridiging header error in swift

Trying to call objective c code in swift code but it don't let me to do, it tell header file is missing.
The easiest way to create an Objective-C bridging header and all the project settings to support it is to add any Objective-C file to your project.
Go to File\New\File…, select iOS\Source\Cocoa Touch Class and then click Next. Enter FakeObjectiveCClass as the Class name and choose NSObject as the subclass. Also, make sure the Language is set to Objective-C! Click Next, then Create.
When prompted Would you like to configure an Objective-C bridging header? select Yes.
You’ve successfully created an Objective-C bridging header. You can delete FakeObjectiveCClass.m and FakeObjectiveCClass.h from the project now, since you really just needed the bridging header.
I got an solution for bridging-header.h file does not exit. Just want to share, hope it may help others too.
Follow below steps:-
First of all delete all header file if you have implemented any.
Add new header file from the ios templet. Hope you know how to add any new file, just follow in same manner.
Now go to the buid setting and there search for objective-c bridging header, simply put the header file name with .h extension too.
please see the image how to add the file name in objective-c Bridging Header
In Xcode, add a new class with Objective-C as the language. When prompted to create a bridging header file, click yes.
You will have a file added to your project named: YourProjectName-Bridging-Header.h.
Add all your imports to this file.
In your Swift classes, import the bridging-header file.

Using TesseractOCR Objective-C framework with Swift iOS App (Bridging Header issues)

I am following this tutorial: http://www.raywenderlich.com/93276/implementing-tesseract-ocr-ios and I am using the latest Xcode (version 7 beta 3) and am having issues with importing the bridging header. I have searched various sites and have found many people posting solutions such as removing a certain setting like the "Objective-C Bridging Header" from the tests target or only putting it in the project or target settings. I have tried to change "no" to "yes" in the Build Settings in "Always Search User Paths", but that to no avail. The framework I added to the project has a "headers" folder and within that is the TesseractOCR.h file. I have tried so many things, I feel that either my issue is some random setting I need to configure or something obvious that I do not know of, with me being a beginner in Swift and no knowledge of Objective C, I would appreciate any guidance.
In my bridging header file I have included
#import <TesseractOCR/TesseractOCR.h>
The two errors I get are
TesseractOCR/TesseractOCR.h file not found
Failed to import bridging header 'pathtoapp/AppName-Bridging-Header.h'
In project navigator press CMD+N (New File) - iOS - Source - Objective-C File - "type any name you want" - Next button - Create button. Then you'll see alert asking you "Would you like to configure an Objective-C bridging header?" - Yes.
Done, now just delete .m file because you don't need it. Thats all :)
add this to Library Search Paths
$(inherited)
$(PROJECT_DIR)/tesseract-ios-lib/lib
Rename the "headers" directory to "Headers" on the TesseractOCR Framework

Swift "Bridging-Header.h" file not allowing me to instantiate objective-c classes in .swift files

When X-code tries to create a bridging header automatically, it crashes every single time, so I followed the instructions on how to manually create a bridging header.
(Create a .h file, name it <#PROJECT_NAME>-Bridging-Header.h, import all the .h files you need?)
Problem is, when I try to instantiate a class in the .swift file that's included in that header, nothing happens (it says that class doesn't exist) Also, in the Bridging Header it doesn't seem to autocomplete my filenames when I try to include them, leading me to believe somethings not linking properly.
Has anyone run into this? Does anyone know how to fix it?
You need to add it to your target's build settings:
In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.
Set "Objective-C Bridging Header" to <#PROJECT_NAME>-Bridging-Header.h
I'm not sure of the correct value for "Install Objective-C Compatibility Header", but it's a yes/no, so you can toggle that if it doesn't work at first.
I tried to create a bridging header myself but for some reason Xcode didn't like it.
So i deleted my custom one, imported an Obj C file which made Xcode ask if I wanted it to create one for me.
I clicked yes, and it worked!
1) create a file called "FMDB-Bridging-Header.h"
inside this file type the following:
#import "FMDB.h"
3) go to Build Settings -> Swift Compiler - Code Generation
- add to 'Objective-C Bridging Header': FMDB-Bridging-Header.h
or if it was placed inside a folder in your project:
FolderName/FMDB-Bridging-Header.h
Add a header file to your project with the name "[your-project-name]-Bridging-Header.h
Go to Build Settings > Build Options and set "Embedded Content Contains Swift Code" to "Yes"
Go to Build Settings > Linking and add "#executable_path/Frameworks" to Runpath Search Paths
Build your project now!
it could help setting the name of the bridging header with its Project root, as "MyProject/MyProject-Bridging-Header.h" into the string value of the Swift Compiler Build key 'Objective-C Bridging Header'

Resources