先在工程根目錄下或是子目錄下創建一個文件夾, 在里面放入一個以 modulemap 為后綴的文件, 比如Module.modulemap.
文件內容模板:
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTV OS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/S DKs/ AppleTVSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPho neOS .sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SD Ks/i PhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX . sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/Watch OS. sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDK s/Wa tchSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
上面都是在引入一個頭文件, 只是針對的平臺不一樣.
然后在 Build Setting 中的 import path 設置中將該文件的文件夾路徑填上即可. 比如我在某個子目錄下新建了一個 iOS 文件夾(路徑是./FoundationExtensions/iOS), 然后再在里面放入 Module.modulemap 文件, 文件內容只是引入了 iOS 端的頭文件:
module CCommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
則 import path 中添加一條內容就是: ./FoundationExtensions/iOS.
混合 swift 和 oc 的庫如何暴露 oc 頭文件: 先在 Build Phases 的 Headers 內將 oc 頭文件加入到 public 一欄中, 然后在 framework 對應的頭文件中 import 即可. 比如 #import "DataConverter.h"