• Swift制作打包framework


    新建framework项目

     

    设置生成fat包,包括模拟器x86_64和arm64

    Buliding Settings -> Architectures -> Build Active Architecture Only 设置为NO

    设置打包环境,选择release

    edit Scheme -> run -> Build configuration 设置为 Release

    设置静态库

     Buliding Settings -> Linking -> Dead Code Stripping 设置为NO

     Buliding Settings -> Linking -> Mach-O Type 设置为Static Library

    创建打包合并framework脚本

    添加打包+合成脚本代码:

    1. # Install dir will be the final output to the framework.
    2. # The following line create it in the root folder of the current project.
    3. FMK_NAME=${PROJECT_NAME}
    4. INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
    5. # Working dir will be deleted after the framework creation.
    6. WRK_DIR=build
    7. DEVICE_DIR=${WRK_DIR}/Build/Products/Release-iphoneos/${FMK_NAME}.framework
    8. SIMULATOR_DIR=${WRK_DIR}/Build/Products/Release-iphonesimulator/${FMK_NAME}.framework
    9. # -configuration ${CONFIGURATION}
    10. # Clean and Building both architectures.
    11. xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME} -configuration Release -derivedDataPath ${WRK_DIR} clean
    12. xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME} -configuration Release -derivedDataPath ${WRK_DIR} -sdk iphoneos -arch arm64 clean build
    13. # simulator
    14. xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME} -configuration Release -derivedDataPath ${WRK_DIR} -sdk iphonesimulator -arch x86_64 build
    15. # Cleaning the oldest.
    16. if [ -d "${INSTALL_DIR}" ]
    17. then
    18. rm -rf "${INSTALL_DIR}"
    19. fi
    20. mkdir -p "${INSTALL_DIR}"
    21. cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
    22. # Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
    23. lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
    24. cp -R "${SIMULATOR_DIR}/Modules/${FMK_NAME}.swiftmodule" "${INSTALL_DIR}/Modules/"
    25. #rm -r "${WRK_DIR}"
    26. open "${SRCROOT}/Products/"

    运行脚本,生成的framework会在项目根目录的Products文件夹下。

    添加swift类到工程

    TestTool.swift

    1. import UIKit
    2. // 可以在模块外被调用
    3. public class TestTool: NSObject {
    4. // 只能在模块中被调用
    5. func HelloWorld(withParam param: String) -> Void {
    6. print(param)
    7. }
    8. // 可以在模块外被调用,只能在swift中被调用
    9. public func publicSayHelloWorld() {
    10. print("sayHelloWorld")
    11. }
    12. open func openSayHelloWorld() {
    13. print("sayHelloWorld")
    14. }
    15. // @objc public 同时修饰,才能在OC项目中被调用;并且也能被swift项目调用
    16. @objc public func sayHelloWorldToOC() {
    17. print("sayHelloWorldToOC")
    18. }
    19. }

    注意添加public修饰符到class,将类暴露出来

    右键生成的framework,选择显示包内容,打开Headers目录下的XXXX-Swift.h,能找到刚刚添加的TestTool。

    1. SWIFT_CLASS("_TtC7TestSDK8TestTool")
    2. @interface TestTool : NSObject
    3. - (void)sayHelloWorldToOC;
    4. - (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
    5. @end

  • 相关阅读:
    python带你采集桌游、剧本杀游戏店数据信息~
    aac转化为mp3,详细的转换步骤
    uniapp开发小程序项目
    mac苹果电脑需要安装杀毒软件吗?
    什么是CDN?什么是安全加速CDN?有什么优势?
    黑豹程序员-h5前端录音、播放
    基于Pytorch框架的LSTM算法(二)——多维度单步预测
    数字孪生技术:智慧港口的未来
    BCGSuite for MFC改进了Edit、ListBox和AnalogClock控件
    旅游业迎来内生式增长 携程三大创新助力高质量发展
  • 原文地址:https://blog.csdn.net/watson2017/article/details/134406828