As the error states, bridging headers are not allowed in Frameworks. The Importing Code from Within the Same Framework Target section of the Mix & Match apple documentation hints at this. As they say, you need to "In your umbrella header file, import every Objective-C header you want to expose to Swift".
To create an Objective-C bridging header file, all you need to do is drag some Objective-C code into your Swift project – Xcode should prompt you with the message "Would you like to configure an Objective-C bridging header?" Click "Creating Bridging Header" and you'll see a file called YourProjectName-Bridging-Header.
Xcode offers to create this header when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app. If you accept, Xcode creates the bridging header file along with the file you were creating, and names it by using your product module name followed by "-Bridging-Header. h" .
As the error states, bridging headers are not allowed in Frameworks. The Importing Code from Within the Same Framework Target section of the Mix & Match apple documentation hints at this. As they say, you need to "In your umbrella header file, import every Objective-C header you want to expose to Swift".
However, I discovered that you may also need to make those specific headers public as well. This answer reviews why and how to do that: Swift compiler error: "non-modular header inside framework module".
So, do this:
Note: The "umbrella header file" is a file (named [ProductName].h) that generally represents all public headers of a framework. It is usually just a list of #import statements to other headers contained in the framework. In Xcode, if you open UIKit.h, you will see a good example of an umbrella file.
There are two possibilities. Adding the necessary headers to the umbrella header file and making them public is one way. However, this is a problem if the headers should be available to Swift, but not public.
The second possibility which will make internal headers available to Swift is described in detail here. Essentially, a module map similar to the following needs to be created:
module AwesomeKitPrivate {
header "../InternalClass.h"
export *
}
This can then be included in XCode using the setting:
SWIFT_INCLUDE_PATHS = $(SRCROOT)/AwesomeKit/ProjectModule
See Importing Objective-C into Swift .
To import Objective-C code into Swift from the same framework
In your umbrella header file, import every Objective-C header you want to expose to Swift. For example:
#import "XYZ/XYZCustomCell.h" #import "XYZ/XYZCustomView.h" #import "XYZ/XYZCustomViewController.h"
Make the included files public in the framework's "Headers" section of its "Build Phases".
Clean and rebuild.
Swift will see every header you expose publicly in your umbrella header. The contents of the Objective-C files in that framework will be available in any Swift file within that framework target automatically, without any import statements. Use your custom Objective-C code with the same Swift syntax you use with system classes.
let myOtherCell = XYZCustomCell()
myOtherCell.subtitle = "Another custom cell"
Important: the "umbrella header file" means the file {ModuleName}.h. BTW, the target name is {ModuleName}.framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With