首页 > 解决方案 > “导入桥接头失败”iOS 单元测试

问题描述

我有一个带有 2 个开发目标和 1 个单元测试目标的 iOS 项目。开发目标是混合的(同时使用 Objective-c 和 Swift),因此我必须Bridging-Header.h在项目中使用。

问题是当我想使用以下代码将模块导入我的单元测试类时:

@testable import <Module>

通过添加上述行,单元测试将停止构建并输出以下错误:

/Users/admin/Projects/<Project>/Tests/<TestClass>.swift:10:18: Failed to import bridging header '/Users/admin/Projects/<Project>/Core_Services_Interfaces/<Module>-Bridging-Header.h'

导入的 Objective-c pod 似乎存在一些问题。解决问题的任何帮助表示赞赏。

PS:我的Podfile

target '<TARGET_1>' do
platform :ios, '8.0'
    inhibit_all_warnings!

    pod 'GoogleAnalytics'
    pod 'GoogleIDFASupport'
    pod 'GoogleAPIClient/Calendar', '~> 1.0.2'
    pod 'GTMOAuth2', '~> 1.1.0'
    pod 'GoogleMaps'
    pod 'MARKRangeSlider'
    pod 'MGSwipeTableCell'
    pod 'KVNProgress'
    pod 'Adjust', '~> 4.11.0'
    pod 'HCSStarRatingView', '~> 1.5'
    pod 'SDWebImage', '~>3.8'
    pod 'MMPopupView'
    pod "MXPagerView"
    pod 'AppAnalytics'
    pod 'MXSegmentedPager'
    pod 'MBProgressHUD', '~> 1.1.0'
    pod 'PKHUD', '~> 4.0'
    pod 'DeviceGuru'

    use_frameworks!
    pod 'Alamofire', '~> 4.7'
    pod 'ObjectMapper', '~> 3.3.0'
    pod 'RealmSwift'
    pod 'netfox'
    pod 'KeychainSwift', '~> 11.0'
    pod 'NVActivityIndicatorView'
    pod "PullToRefreshKit" , "~> 0.6.0"
    pod 'MaterialShowcase'
    pod 'Segmentio', '~> 3.2'

    target '<TARGET_2>' do
        inherit! :complete
    end

    target '<TEST_TARGET>' do
        inherit! :complete
    end

    post_install do |installer|
        installer.pods_project.targets.each do |target|
            if target.name.include?('MaterialShowcase')
                target.build_configurations.each do |config|
                    config.build_settings['SWIFT_VERSION'] = '3.2'
                end
            end
        end
    end
end

标签: iosxcodeunit-testingcocoapodsobjective-c-swift-bridge

解决方案


推荐阅读