I have created two targets of my application i.e Dev and Prod. How can I add bridging header to it for both the version? Is one bridging header is works for both or I have to create two for different targets?
You can add bridging these steps.
Select Target -> Build Settings -> Objective-C Bridging Header -> fill the specified field.
Please follow the steps below to add Swift Bridging Header in your project,
Add a new file to Xcode (File > New > File), and select Source and choose Header File
Create your file ProjectName-Bridging-Header.h
In Build Settings, Next to Objective-C Bridging Header you need to add the path of your header file. i.e ProjectName/ProjectName-Bridging-Header.h or ProjectName-Bridging-Header.h.
Import your Objective-C classes using #import <Class Name>
In Swift you can use the "#if/#else/#endif" in Bridging Header file.
#if DEBUG
#import "devVersion.h"
#else
#import "prodVersion.h"
#endif
"Now, you must set the "DEBUG" symbol elsewhere, though. Set it in the "Swift Compiler - Custom Flags" section, "Other Swift Flags" line. You add the DEBUG symbol with the -D DEBUG entry.
As usual, you can set a different value when in Debug or when in Release."
Ref: https://stackoverflow.com/a/24152730/3089616
Hope this help!
Related
I'm trying to add mupdf framework to a swift project. I created a new project and copied the mupdfdk.framework to my project and referenced it in the frameworks section. Following is a screenshot of the documentation.
Now my project looks like this.
Then when I try to import it in viewcontroller, I get Could not build Objective-C module 'mupdfdk' error. Are there any other steps I'm missing? Please help.
You need to add this bridging header:
MuPDF-Bridging-Header.h
#ifndef MuPDF_Bridging_Header_h
#define MuPDF_Bridging_Header_h
#import "mupdfdk.framework/Headers/mupdfdk.h"
#endif /* MuPDF_Bridging_Header_h */
and declare it within the Swift Compiler section of the Build Settings:
have been trying to import a header file for database.
I'm getting two errors.
'FMDB.h' file not found
and
ailed to emit precompiled header '/Users/myname/Library/Developer/Xcode/DerivedData/zzzzzz- for bridging header '/Users/myname/Library/Autosave Information/zzzzzz/header.h'
The full path of FMDB.h is the below
/Users/myname/Library/Autosave Information/zzzzzz/fmdb/FMDB.h
In Objective-C Bridging Header : header.h
in the header file, the codes are :
#ifndef Header_h
#define Header_h
#import "FMDB.h"
#endif /* Header_h */
I set Allow Non-modular Includes in Framework Modules as Yes.
It didn't work out for me tho.
Follow a few steps:
Rename your header to --> YourProjectName-Bridging-Header.h
Check/Add Path of this header in your Build Setting --> Under Objective-CBridging Header (You may drag the file path)
Framework Modules as No
Then build, it should work. thanks!
I recently moved to new Mac book with Apple M1 Max chip and got the same error. I resolved it by removing arm64 from EXCLUDED_ARCHS in Build Settings.
I'm trying to Archive my project but I can't because this error:
/Users/username/Developer/clickbalance/cb-ventas/CB Ventas/CB Ventas/Header.h:12:9: error: 'StarIO_Extension/StarIoExt.h' file not found
#import <StarIO_Extension/StarIoExt.h>
^
<unknown>:0: error: failed to import bridging header '/Users/username/Developer/clickbalance/cb-ventas/CB Ventas/CB Ventas/Header.h'
** ARCHIVE FAILED **
I tried everything like the other questions says about a similiar error like this question: Getting "file not found" in Bridging Header when importing Objective-C frameworks into Swift project
But nothing work.
Here is the location of the framework and the header file:
I linked the .frameworks files in the Link Binary With Libraries too.
This is my header file:
#import <Foundation/Foundation.h>
#ifndef StarIO_Extension_Bridging_Header_h
#define StarIO_Extension_Bridging_Header_h
#import <StarIO_Extension/StarIoExt.h>
#import <StarIO_Extension/StarIoExtManager.h>
#endif /* StarIO_Extension_Bridging_Header_h */
The Objective-C Bridging Header I set to ${PROJECT_DIR}/CB Ventas/Header.h and is set at the Target level, and NOT the Project level
I'm using Cocoapods too.
How can I solve that problem to archive the project?
Make sure you have the framework checkbox checked for the target you are trying to archive in the Utilities pane -> Target Membership:
I'm trying to add a Swift file to my app and get a "Failed to import bridging header" error, among others.
Bridging-Header code:
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "Menu.h"
In build settings, try setting "Embedded Content contains Swift Code" to Yes.
Also, it looks like its failing to recognize objects from UIKit, so try adding "import UIKit" atop one of your Swift files.
My team has a few full Obj-C libraries we like te reuse in our projects. To do so, we usually set up a git submodule, and then add it to the xcode project as a sub-project (Using target dependency, link binary with library and updating the User Header Search Paths)
So far it's only been done in full Obj-C projects, and I'm now trying to use it in a Swift project but with very little success so far. I tried to add the briding-header file, referenced it in the project and filled it like so :
#import "MyLibraryHeader.h"
With the target header being in the User Header Search Paths.
It lets me build, but when using it in my Swift files:
let test = MyLib();
let secondTest = MyLib.classMethod1("some_arguments");
I get an EXC_BAD_INSTRUCTION on secondTest, and the following logs in the debugger:
(lldb) po test
error: <EXPR>:1:1: error: use of unresolved identifier 'test'
(lldb) po secondTest
error: Error in auto-import:
failed to get module 'MyProject' from AST context:
/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h:12:9: error: 'MyLibraryHeader.h' file not found
#import "MyLibraryHeader.h"
^
failed to import bridging header '/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h'
Found the following question with no answer : Xcode 6 crashing when using Objective-C subproject inside Swift
Any help would be appreciated.
I followed the HockeyApp tutorial that can be found here:
http://support.hockeyapp.net/kb/client-integration-ios-mac-os-x/integrate-hockeyapp-for-ios-as-a-subproject
In the end, I was on the right tracks but messed up the Header Search Paths:
Add subproject xcodeproj to the workspace
On the main project : Link binary with library, and add the subproject product library (Bonus points : add it as a target dependency too)
Update Header Search Paths (not User Header Search Paths) accordingly
Import your Library.h in the main project Bridging-Header.h file
What threw me off for a while is that the Swift Compiler setting for the Objective-C Bridging Header was not set automatically. Check the Build Settings for your target and ensure the "Objective-C Bridging Header" setting is not blank.