swift制作framework静态库教程与注意事项

本文详细介绍了如何在Xcode中创建Swift静态库,设置相关参数,包括设置为静态库、版本号、生成fat包,以及处理DeadCodeStripping。此外,还展示了创建系统类扩展,并提供了脚本自动化合并framework的步骤,包括解决合并过程中遇到的问题。最后,讲解了在Swift和Objective-C项目中如何引用和使用这个静态库。


之前我写了一篇名为:xcode写framework静态库脚本文件合并fat文件教程和踩坑
的文章:https://blog.csdn.net/boildoctor/article/details/112259356
但还是没说具体怎么用swift建立framework静态库,这里补上教程:

新建项目

File->new->Project->Framework,起一个项目名,语言选择swift 如下图
在这里插入图片描述
在这里插入图片描述

设置相关参数

1.设置静态库

build settings -> Mach-O Type设置(Static Library) ,如下图
在这里插入图片描述

2.设置版本号

general->Deployment Info -> 设置 ios9.0,
在这里插入图片描述

3. 设置生成fat包

Build Active Architecture Only(NO,生成fat包,包括模拟器x86_64和arm64)
在这里插入图片描述

4. Dead Code Stripping(NO)

在这里插入图片描述

创建swift系统类扩展

新建文件一个swift文件,起名UIView+AnimateExtension.swift,这个系统类扩展作用就是执行以后可以直接摇动UIView

//
//  UIView+AnimateExtension.swift
//  tdwUIView+AnimateExtension
//
//  Created by tdw on 2021/1/5.
//

import UIKit

extension UIView{
   
   
    /**
     摇动当前view水平方向
     */
    @objc public func shakeAnimationH() {
   
   
        // 抖一抖
        self.layer.removeAnimation(forKey: "error")
        let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
        animation.values = [-16, 0, 16, 0]
        animation.duration = 0.2
        animation.repeatCount = 3
        self.layer.add(animation, forKey: "error")
    }
    /**
     摇动当前view水平方向
     */
    @objc public func shakeAnimationH(duration:Double,repeatCount:Float) {
   
   
        // 抖一抖
        self.layer.removeAnimation(forKey: "error")
        let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
        animation.values = [-16, 0, 16, 0]
        animation.duration = duration
        animation.repeatCount = repeatCount
        self.layer.add(animation, forKey: "error")
    }
    /**
     摇动当前view垂
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值