I created a question for this on stack overflow here is the content:
I created an objective-c pod with two files:
Source/SomeViewController.h
Source/SomeViewController.m
I also created a bridging header in the pod:
Source/Bridging-Header.h
with the content:
#import "SomeViewController.h"
My podspec looks like this:
Pod::Spec.new do |s|
s.name = 'TestLib'
s.version = '0.0.1'
s.license = 'MIT'
s.ios.deployment_target = '7.0'
s.source_files = 'Source/*.{h,m}'
s.requires_arc = true
s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => 'Source/Bridging-Header.h' }
end
I created a demo project did pod init and inserted my pod. Then after pod install I get the following output:
Installing TestLib 0.0.1 (was 0.0.1) Generating Pods project Integrating client project
[!] The TestLibProject [Debug] target overrides the SWIFT_OBJC_BRIDGING_HEADER build setting defined in Pods/Target Support Files/Pods-TestLibProject/Pods-TestLibProject.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the$(inherited)` flag, or
- Remove the build settings from the target.
[!] The TestLibProject [Release] target overrides the SWIFT_OBJC_BRIDGING_HEADER build setting defined in Pods/Target Support Files/Pods-TestLibProject/Pods-TestLibProject.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the$(inherited)` flag, or
- Remove the build settings from the target.
When I open my TestLibProject.xcworkspace file I see that the pod was installed correctly but the bridging header from the pod is not installed correctly. I my Swift project I tried to do:
let vc: SomeViewController
This gives an error because the bridging header from the pod ist not installed.
How do I have to configure the podspec in order to get the bridging header of the pod being installed correctly?
It seems that when you use:
s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => 'Source/Bridging-Header.h' }
the bridging header from the pod is not included correctly.
Because that's not the correct path to the source managed by CocoaPods :)
What is the correct path?
My sources are organized as:
/TestLib/testLib.podspec
/TestLib/Source/SomeViewController.h
/TestLib/Source/SomeViewController.m
/TestLib/Source/Bridging-Header.h
It'll be something like ${POD_ROOT}/POD_NAME/Bridging-Header.h, presuming you added it to your preserve_paths
I also tried the following all did not work:
s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => '${PODS_ROOT}/Source/BridgingHeader.h' }
s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => '${PODS_ROOT}/BridgingHeader.h' }
@segiddins I also tried:
s.preserve_paths = "BridgingHeader.h"
s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => '${POD_ROOT}/TestLib/BridgingHeader.h' }
Did not work. any other idea?
Maybe '${POD_ROOT}/TestLib/Source/BridgingHeader.h' ?
I tried that too. Do you have a working example somewhere. I haven't found any on the internet.
I've not yet tried a custom bridging header for a library, sorry.
Then I suppose it really is a bug. It is not working.
+1 looking also for a solution on that!
@steffimueller Could you please share your Podfile as well or tell us which integration strategy you are using (frameworks/libraries)?
Whatever integration works I don't care you can decide. Here is my podspec:
Pod::Spec.new do |s|
s.name = 'TestLib'
s.version = '0.0.1'
s.license = 'MIT'
s.summary = '...'
s.homepage = '...'
s.authors = { '...' => '...' }
s.social_media_url = '...'
s.source = { :git => '...', :tag => '0.12.0' }
s.ios.deployment_target = '7.0'
s.source_files = '*.{h,m}'
s.requires_arc = true
s.preserve_path = "${POD_ROOT}/TestLib/BridgingHeader.h"
s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => '${POD_ROOT}/TestLib/BridgingHeader.h' }
end
And my pod file:
# Uncomment this line to define a global platform for your project
# platform :ios, '6.0'
target 'TestLibProject' do
pod 'TestLib', :path => '/Users/mg/Downloads/Apps/TestLib'
end
This actually works correctly, the problem is stated in the warnings you reported in the original comment:
[!] The TestLibProject [Debug] target overrides the SWIFT_OBJC_BRIDGING_HEADER build setting defined in Pods/Target Support Files/Pods-TestLibProject/Pods-TestLibProject.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the$(inherited)` flag, or
- Remove the build settings from the target.
Your application target has its own custom build setting for SWIFT_OBJC_BRIDGING_HEADER, so the one from your Pod's XCConfig setting cannot be used, hence the warning. As this setting doesn't support inheritance, you'll have to remove the build settings from your target for the Pod's setting to take effect.
Is there a way to use both settings for bridging header together?
Since there can be only one bridging header per target, no
Is there any other way to do that?
The best course of action is probably to eliminate the need for bridging headers entirely by integrating as frameworks, see https://guides.cocoapods.org/syntax/podfile.html#use_frameworks_bang and http://blog.cocoapods.org/CocoaPods-0.36/
@neonichu How can I integrate code as a framework using Swift and objective-c code?
I'm having the same issue that's described here, and I'm not sure it's working as intended. I think y'all are talking about two different things:
I'm trying to bridge a subset of my Objective-C code to Swift by specifying a SWIFT_OBJC_BRIDGING_HEADER in my Framework's Podspec, but that change is erroneously propagating into my application targets, causing these warnings.
Does this bug make a little more sense now?
Nevermind, swiftc doesn't like that:
error: using bridging headers with framework targets is unsupported
@paulrehkugler yah, the issue should also be solved by the new split of XCConfig settings into pod_target_xcconfig and user_target_xcconfig — but doesn't help in this case because lack of support inside swiftc
Hey guys, is there any update on this ? Has swiftc support improved or there's still no way to have this setting on a Cocoapod? Thanks :)
The situation is still the same, the only way to import headers into a Swift framework is via the umbrella header.
@neonichu Can you please provide some insight into how to do this, or point me in the right direction? I'm encountering this issue while trying to include libxml2 in a Swift-based pod.
@alecananian in the case of a system library for which Apple doesn't provide a module map, I'd suggest the approach outlined in https://github.com/ZaBlanc/RaptureXML/issues/69
I met the same problem and asked for a solution
Most helpful comment
Whatever integration works I don't care you can decide. Here is my podspec:
And my pod file: