I am using libzBar for scanning QRCode in swift but I am getting these errors.
.
First error is about weak referencing and second is undeclared type.
At first I thought I haven't included the ZBarReaderView.h but after checking the file Inspector I found that the files are correctly added as
I have already added a ZBarReaderView in Objective-C and it works fine. I have also viewed the sample project for adding an EmbeddedReader(ObjectiveC).
So I want to know why I am getting this error and how to remove this error?
Solution:
To import a set of Objective-C files in the same app target as your
Swift code, you rely on an Objective-C bridging header to expose those
files to Swift. Xcode offers to create this header file when you add a
Swift file to an existing Objective-C app, or an Objective-C file to
an existing Swift app.
It looks like you didn't create a bridging header. Follow the Apple Docs to create one and then import ZBarReaderView.h in the bridging header.
Related
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.
I'm doing an iPad app using swift. But I have some classes which are already developed in objective-c. Now the problem is even after I'm importing objective-c class in bridging header it is showing error in swift file where I need to use objective c variables. I'm showing the project structure and bridging header's content along with the error below.
the folder structure is like
and the bridging header's content is
#import "SObjectData.h"
#import "SObjectDataSpec.h"
#import "SObjectData+internal.h"
the following is CallSObjectData.swift where i'm actually getting issue.there might be a small mistake.
If the I set
swift compiler - code generation
as follows
I'm getting the following issue.
If the I set
swift compiler - code generation
as follows
It is giving me the file doesn't exist error
Please help me finding the bug. thanks in advance.
Make sure click on project file in left pane file explorer. Target -> Build Settings -> under field Swift Compiler - Code Generation make sure your bridging file path is correct.
I'm working on a React Native app and I'm trying to use a module called react-native-socketio.
In order to proceed with the app, I will need to bridge the objective C header in Xcode but the related section is missing.
According to the tutorial
I have also noticed that the section Swift Compiler – Code Generation is also missing from Xcode.
Why?
I have resolved this matter by first adding a new swift file to the project, then the respective section appeared.
As you can probably tell, I now have an empty Swift file just sitting inside my project folder and options to bridge my header file.
Thanks for the help everyone.
Looks like you have created an ObjectiveC project instead of Swift (I can see the AppDelegate.h & AppDelegate.m). ObjC project wont have Swift Compiler section. Select Swift as language while creating project
I must have started from scratch about 4 times already. I've followed the solutions listed below but I still have an issue (which I think has something to do with the bridging header file).
Note: I have tried manually creating the bridging header as well as the automated solution Xcode offers when you drag some Objective-C files into a Swift project.
Swift Bridging Header import issue
Connect Objective C framework to Swift iOS 8 app (Parse framework)
Here are the main errors I am seeing. I've tried moving the header file up a level/down a level and it still claims to not see it. Everything is currently where Xcode put it when I selected "Yes" when prompted to created the bridging header automatically. You can also see the full contents of my bridging header.
The "Cannot find protocol declaration for NSObject" error usually refers to circular references problems.
I'm wondering why you put all those standard Apple frameworks in the bridging header? This might be the problem. This special file is supposed to "bridge" Swift and Objective C worlds together, so if you've already referenced and linked your app against those frameworks in your Swift code, you shouldn't need to do it again in the bridging header.
Try to remove all Apple-provided frameworks from your bridging header and only leave the specific ones (IBM....h), and see if it works?
If it doesn't, then start with Foundation/Foundation.h only...
I have a framework with Swift and Objective-C in it. I have the statement at the top of my Objective-C class #import "MyFrameworkHeader.h" which I thought would expose my swift code to my Objective-C class however the compiler still says the symbols don't exist, how can I expose my Swift classes to my Objective-C classes within the same Framework?
Ugh, after smacking my head for a few hours then finally posting this question, within a few minutes I found the answer:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_82
Under the header: "Importing Swift into Objective-C"
To get Objective-C to register your swift code you should go into your build settings and then see/set your project name, also see if the compatibility header option is checked to yes.
after that is set just go into your file and type #import "-Swift.h". I don't think you can import individual files with swift and Objective-C, you import all of your swift files at once. It's important that you make sure all of your swift files have no errors or you will get an error about this header not being defined. You might have to build your project with no errors for the file to get generated at least once.
I think what you're looking for is a Bridging Header.
This is a file that you import your Objective-C headers into that get exposed to Swift.
There are 2 ways to make one (as far as I know):
The easiest way, in my opinion, is to add an existing Obj-C file to your swift project, or vice-versa. Xcode should ask you if you want to automatically configure a bridging header. Choose yes, and Xcode should make a file called something like 'project name'-bridging-header.h. In this file, import your files, so #import "MyFrameworkHeader.h" should do it.
Make your own empty file with File > New File (Cmd+N) > Source > Header File. Call it whatever, and import your files like in the previous one. Before it will work, you have to enter the name of your bridging header file into a field in your Project Settings (In the first option, Xcode will do it for you).