Need help to resolve error "using bridging headers with framework targets is unsupported"

Hi,

I have added swift file to existing framework project. In swift code I want to access sqlite3 data base.Now to import sqlite header file in swift I have followed below steps.


1) Created Bridging header file and added into project target.

2)Added import statement to header file "#import <sqlite3.h>"

3) This header is marked as public in Build Phases

4) Added header file name with path in "Objective-C Bridging Header" in project target build setting under "Swift Compiler - Code Generation"


Now when I build project I get compilation error as

<unknown>:0: error: using bridging headers with framework targets is unsupported

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1



Does any one faced simiral kind of issue earlier?

Any one aware about fixing this xcode compiler issue.

Thanks in Advance.

Post not yet marked as solved Up vote post of Learner Down vote post of Learner
24k views

Replies

As the error says, bridging headers aren't allowed in frameworks, only in applications.


The detailed documentation is here:

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID130


The Swift code will be able to access everything from objc that is included in the public umbrella header for your framework where it says

// In this header, you should import all the public headers of your framework using statements like #import <YourFramework/PublicHeader.h>

You'll need to remove the bridging header from where you added it in the Build Settings, in order to get your framework to compile.



Using the SQLite3 library in your Swift code is a different problem. As far as I know, it still requires the workaround described here:

http://stackoverflow.com/a/29189873/86910

I can't edit my post at the moment, but there may be a different workaround required now to properly link libraries like SQLite3:


https://forums.developer.apple.com/message/9366#9366

Thanks LCS for help and reference links.

Hello. I am having exactly the same issue.
I am using Unity3D game engine to build an iOS XCode project, so I don't really know how swift even works! Consequently, it is very difficult for me to fix this issue, so I would appreciate if you gave me a more precise fix for this problem please.

Thanks a lot for your time!!

Your Framework Umbrella Header will declare import of Frameworks that are needed for your Framework just like an App would do ..

but .. !!

Bridging means usually Objective-C to Swift. Exactly this is not supported to avoid the resulting mess. So you can not!

But you can "publish" your additional Headers via Target Membership by clicking [x] and select option "public" or Drag 'n Drop those Headers into Build Phase -> Headers -> Public

Once you did that they will be part of the Framework as a copy, but their location will be also relative to the Framework. Which means in case those Headers have relative imports to each other.. like some ExampleA-header.h file imports some ExampleB-header.hfile then you need to change some import rules like..

// ExampleA-header.h
#import "subfoldername/subfoldername/ExampleB-header.h" //oops, this will not work
#import "FrameworkName/ExampleB-header.h" //cool, this will work.

and such resulting ExampleA-header.h file could be import'ed in the Umbrella Header with..

// Framework Umbrella Header
// Frameworks this Framework needs.
#import <Foundation/Foundation.h>

//your own header, see here we use < & >
#import <FrameworkName/ExampleA-header.h> 

//! Project version number for FrameworkName.
FOUNDATION_EXPORT double FrameworkNameVersionNumber;

//! Project version string for FrameworkName.
FOUNDATION_EXPORT const unsigned char FrameworkNameVersionString[];

//here you can declare Class interfaces that you want to use as wrapper/interface to your inner workings when your framework is used in another app.
@interface MyFrameworkName : NSObject 
@property (nonatomic) FantasyType *fantasyValue;
@end

when you still get the error message then you have to change Build Settings in Xcode for your particular Framework Targeted Project. For this you can search for Build Settings of SWIFT_OBJC_BRIDGING_HEADER and erase some possibly accidentally $(PROJECT_DIR)/ProjectName-Bridging-Header.h entry.

As long your framework target build settings contain such entry the error will always appear. Be careful when you have multiple Targets in your Project, because you might erase your Bridging entry for other Targets as well.. so make sure you are in the right Column of this particular Framework Target when you erase this ...Bridging-Header.h... entry..