当前位置: 首页 > news >正文

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脚本

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

# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
FMK_NAME=${PROJECT_NAME}
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Build/Products/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Build/Products/Release-iphonesimulator/${FMK_NAME}.framework# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME}  -configuration Release -derivedDataPath ${WRK_DIR} cleanxcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME} -configuration Release -derivedDataPath ${WRK_DIR} -sdk iphoneos -arch arm64  clean build
# simulator
xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME} -configuration Release -derivedDataPath ${WRK_DIR} -sdk iphonesimulator -arch x86_64 build# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fimkdir -p "${INSTALL_DIR}"cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"cp -R "${SIMULATOR_DIR}/Modules/${FMK_NAME}.swiftmodule" "${INSTALL_DIR}/Modules/"#rm -r "${WRK_DIR}"open "${SRCROOT}/Products/"

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

添加swift类到工程

TestTool.swift

import UIKit// 可以在模块外被调用
public class TestTool: NSObject {// 只能在模块中被调用func HelloWorld(withParam param: String) -> Void {print(param)}// 可以在模块外被调用,只能在swift中被调用public func publicSayHelloWorld() {print("sayHelloWorld")}open func openSayHelloWorld() {print("sayHelloWorld")}// @objc public 同时修饰,才能在OC项目中被调用;并且也能被swift项目调用@objc public func sayHelloWorldToOC() {print("sayHelloWorldToOC")}
}

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

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

SWIFT_CLASS("_TtC7TestSDK8TestTool")
@interface TestTool : NSObject
- (void)sayHelloWorldToOC;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

http://www.lryc.cn/news/234274.html

相关文章:

  • 无线WiFi安全渗透与攻防(N.2)WPA渗透-使用airolib-ng创建彩虹表加速
  • 整形数据和浮点型数据在内存中的存储差别
  • 【Python基础篇】运算符
  • 开启数据库审计 db,extended级别或os级别)并将审计文件存放到/opt/oracle/audit/下
  • 02.webpack中多文件打包
  • IEEE Standard for SystemVerilog Chapter 22. Compiler directives
  • 机器学习中的独立和同分布 (IID):假设和影响
  • PTP软硬件时间戳
  • 使用ADS进行serdes仿真时,Tx_Diff中EQ的设置对发送端波形的影响。
  • 数据库迁移(DBeaver版本)
  • 【c++STL常见排序算法sort,merge,random_shuffle,reverse】
  • STM32/N32G455国民科技芯片驱动DS1302时钟---笔记
  • 基于PLC的污水厌氧处理控制系统(论文+源码)
  • Unity之NetCode多人网络游戏联机对战教程(9)--NetworkAnimator组件
  • iceoryx之Roudi
  • .Net(C#)常用转换byte转uint32、byte转float等
  • windows快捷方式图标变成空白
  • 【Linux系统编程十九】:(进程通信)--匿名管道/模拟实现进程池
  • 【全网首发】2023年NOIP真题
  • 【Linux网络】从原理到实操,感受PXE无人值守自动化高效批量网络安装系统
  • Pandas+Matplotlib 数据分析
  • k8s ingress高级用法一
  • C语言--从键盘输入10个数字放在数组中,并输出
  • SSL加密
  • 一个美观且功能丰富的 .NET 控制台应用程序开源库
  • DispatcherSynchronizationContext and Dispatcher
  • java类型属性set方法无法被赋值
  • 【2】SM2验签工具和RSA验签工具
  • Python (十一) 迭代器与生成器
  • 通过maven命令手动上传jar私服Nexus