我创建了一个包含两个文件的 objective-c pod:
Source/SomeViewController.h
Source/SomeViewController.m
我还在 pod 中创建了一个桥接头:
Source/Bridging-Header.h
内容:
#import "SomeViewController.h"
我的 podspec 看起来像这样:
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
我创建了一个演示项目并执行了 pod init
并插入了我的 pod。然后在 pod install
之后我得到以下输出:
正在安装 TestLib 0.0.1(原为 0.0.1) 生成 Pod 项目 整合客户项目
[!] 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.
当我打开我的 TestLibProject.xcworkspace
文件时,我看到 pod 已正确安装,但 pod 的桥接头安装不正确。我尝试做我的 Swift 项目:
let vc: SomeViewController
这会产生一个错误,因为来自 pod 的桥接头未安装。
我必须如何配置 podspec
才能正确安装 pod 的桥接 header ?
最佳答案
Podspecs 构建框架,框架不能包含桥接 header 。如果您想将非模块化代码导入 Swift 框架,则需要使用自定义模块映射,例如 MyLib/module.modulemap:
framework module MyLib {
umbrella header "MyLib.h"
// Load an SDK header, e.g. CommonCrypto.h
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
module * { export * }
}
在那里,您可以在 Xcode 项目中指定自定义模块映射(作为 .xcconfig 文件中的 MODULEMAP_FILE
设置,或作为 目标build设置的模块映射文件。
现在,最后一 block 拼图:podspec。您需要设置 module_map
:
Pod::Spec.new do |s|
# …
s.module_map = 'MyLib/module.modulemap'
end
以上就是如何SQLite.swift以通用框架和 pod 的形式分发自身。
编辑: 似乎我错过了原始问题的要点,已澄清 in this thread . OP 希望使用 pod 框架的桥接头自动将自身加载到安装项目的 Swift 代码中。这是不可能的。即使 Swift 框架确实支持桥接 header ,它们也只能将 Objective-C/C 代码(即私有(private)框架代码)加载到框架的 Swift 代码中。 p>
关于ios - 包含 Pod 的桥接头以构建项目目标的设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30608575/