Contents
  1. 1. Swift使用Carthage替代CocoaPods
    1. 1.1. 集成
      1. 1.1.1. 通过 Homebrew 安装
      2. 1.1.2. 项目配置文件
        1. 1.1.2.1. 配置依赖库
    2. 1.2. 编译第三方库
    3. 1.3. 导入第三方库
    4. 1.4. 一些坑
      1. 1.4.1. 01: has no shared framework schemes

Swift使用Carthage替代CocoaPods

官方地址: https://github.com/Carthage/Carthage
参考文章: https://www.jianshu.com/p/76b9ff09f99c

集成

通过 Homebrew 安装

1
brew install carthage

项目配置文件

和使用CocoaPods一样, 这里也需要一个无后缀的配置文件 Carthfile

配置依赖库

熟悉Podfile的话这里就不会陌生了

1
github "Alamofire/Alamofire"
  • 对于github指名后会去github上找对对应的库
    • 格式: github Username/ProjectName
  • git 支持http:// git:// ssh://

== 毫无疑问是说必须为指定版本,如果没有,就不下载编译;
>= 使用大于或等于指定版本的库,如果有最新,则使用最新的;
~> 则是一个开区间,如“~>1.1.0”则会返回“1.1.1~1.9.9”之间的版本,不包括2.0.0;

编译第三方库

类似pod install操作, cd 到工程目录执行下面命令

1
carthage update --platform iOS
  • 一般这里指定一下平台好些,否则会编译出mac,tv,iOS个平台的,完全没必要

  • 执行完成后会看到有个Carthage目录

    • build中就是编译好的第三方库
    • Checkouts中是第三方库的缓存

导入第三方库

手动将Carthage/Build中的framework加到项目中



先在就阔以在项目中使用Alamofire

一些坑

01: has no shared framework schemes

1
2
*** Skipped building R.swift due to the error:
Dependency "R.swift" has no shared framework schemes for any of the platforms: iOS
  • 因为Carthage需要库工程的Scheme需要为Shared
  • 没有的话可能是因为git忽略了相应文件 xcuserdata

参考

https://stackoverflow.com/questions/35054788/carthage-no-shared-framework-schemes-for-ios-platform-for-my-own-framework
https://www.jianshu.com/p/a7defcf2e327

Contents
  1. 1. Swift使用Carthage替代CocoaPods
    1. 1.1. 集成
      1. 1.1.1. 通过 Homebrew 安装
      2. 1.1.2. 项目配置文件
        1. 1.1.2.1. 配置依赖库
    2. 1.2. 编译第三方库
    3. 1.3. 导入第三方库
    4. 1.4. 一些坑
      1. 1.4.1. 01: has no shared framework schemes