美文网首页
Carthage安装与使用

Carthage安装与使用

作者: CoderCurtis | 来源:发表于2020-06-17 17:26 被阅读0次

    一. 安装Carthage

    1. 需要安装homebrew,相关教程可自行搜索

    2. 安装

    1). 终端执行

    brew install carthage
    

    2). 安装完成后 查看版本号

    carthage version
    
    image.png

    二. 使用

    1. 进入项目所在文件夹
    cd 项目路径
    

    例如:

    cd Desktop/Carthage-Test
    
    1. 创建空的Cartfile文件(类比CocoaPods的Podfile)
    touch Cartfile
    
    1. 打开Cartfile文件

    1). 终端中直接执行命令打开

    open Cartfile
    

    2). 项目中找到Cartfile文件使用Sublime等编辑器打开
    3). 使用命令用Xcode打开

    open -a Xcode Cartfile
    
    1. 编辑Cartfile文件
    github "SnapKit/SnapKit" ~> 5.0.0
    github "Alamofire/Alamofire" ~> 5.2
    
    1. 保存并关闭Cartfile文件 使用Cartfile安装
    Carthage update --platform iOS
    
    image.png
    1. 打开Carthage查看生成的文件目录
    open Carthage
    
    image.png

    Carthage/Build: 编译出来的Framework二进制代码库 ----用于导入
    Carthage/Checkouts:从github获取的源代码

    1. 配置项目
    image.png image.png image.png image.png
    1. 添加编译脚本

    1). Build Phases -> '+' -> New Run Script Phase
    2). 添加脚本: /usr/local/bin/Carthage copy-frameworks
    3). 添加Input Files:
    $(SRCROOT)/Carthage/Build/iOS/Alamofire.framework和$(SRCROOT)/Carthage/Build/iOS/SnapKit.framework

    image.png image.png
    1. 编译成功,即可在项目中使用了
    image.png
    1. 更新第三方库:
    carthage update 库名
    

    例如: carthage update SnapKit

    更新多个,以空格分隔:

    carthage update 库名 库名
    

    例如: carthage update SnapKit Alamofire

    Demo

    参考: IOS Carthage安装、使用
    Carthage使用

    相关文章

      网友评论

          本文标题:Carthage安装与使用

          本文链接:https://www.haomeiwen.com/subject/rpjsxktx.html