Search code examples
swiftcocoapodsobjc-bridging-header

CocoaPods Bridging Header file not found


New developer here, and I'm currently building an app in swift. We are using cocoapods, but after running pod install, we get an error in the objective-c bridging header saying that the file cannot be found, but for any and every file in our bridging header. For example, we use DateTools. We pod install it, in the bridging header we put: #import <DateTools/DateTools.h> but then, upon running, it errors, saying that 'Datetools/Datetools.h' file not found. I've already looked through a lot of other similar posts (like this, this, or this), but none have solved the issue. Any help would be greatly appreciated!


Solution

  • When using the use_frameworks! instruction in Cocoapods, the bridging header is not required for importing Objective-C pods in Swift.

    Simply set your desired pods into your podfile:

    #Uncomment this line to define a global platform for your project
    platform :ios, '9.0'
    #Uncomment this line if you're using Swift
    use_frameworks!
    
    target 'YourProject' do
    
    #Swift Pods
    pod 'Alamofire'
    pod 'ActiveLabel'
    
    #ObjC Pods
    pod 'IDMPhotoBrowser'
    pod 'Firebase'
    
    #This stuff is to set the SWIFT_VERSION
    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '2.3'
            end
        end
    end
    end
    

    Run pod install. Run pod update (should not be necessary, but for some reason I'm getting updates almost every time, even after clean install). Close Xcode and reopen using the white xcworkspace file.

    enter image description here

    import Alamofire
    import ActiveLabel 
    import IDMPhotoBrowser
    import Firebase
    

    Done.