[英]Include Pod's Bridging-Header to Build Settings of Project's Target?
我用兩個文件創建了一個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
我創建了一個演示項目 do pod init
並插入了我的 pod。 然后在pod install
我得到以下輸出:
安裝 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.
當我打開TestLibProject.xcworkspace
文件時,我看到 pod 已正確安裝,但 pod 的橋接頭未正確安裝。 我嘗試做的 Swift 項目:
let vc: SomeViewController
這會產生錯誤,因為未安裝來自 pod 的橋接頭。
我必須如何配置podspec
才能正確安裝 pod 的橋接頭?
Podspecs 構建框架,框架不能包含橋接頭。 如果要將非模塊化代碼導入 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 Settings的模塊映射文件。
現在,拼圖的最后一部分:podspec。 您需要設置module_map
:
Pod::Spec.new do |s|
# …
s.module_map = 'MyLib/module.modulemap'
end
以上是SQLite.swift 自我分發的方式,既作為通用框架又作為 pod。
編輯:似乎我錯過了原始問題的重點,正如在此線程中闡明的那樣。 OP 希望使用 pod 框架的橋接頭自動將自身加載到安裝項目的 Swift 代碼中。 這是不可能的。 即使 Swift 框架確實支持橋接頭,它們也只能將 Objective-C/C 代碼(即私有框架代碼)加載到框架的 Swift 代碼中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.