Cathage

在專案目錄下建立Cartfile

在iOS專案目錄下建立 Cartfile

github "Alamofire/Alamofire" ~> 2.0
github "onevcat/Kingfisher" >= 1.5
github "emaloney/CleanroomLogger"
github "thoughtbot/Argo"

執行builing

carthage update --platform ios

kent@Kents-MacBook-Pro ~/d/t/CartageTut> carthage update --platform ios
*** Fetching Argo
*** Fetching CleanroomLogger
*** Fetching Kingfisher
*** Fetching Alamofire
*** Fetching CleanroomASL
*** Checking out CleanroomLogger at "1.5.3"
*** Checking out CleanroomASL at "1.3.3"
*** Checking out Alamofire at "2.0.2"
*** Downloading Argo at "2.0.0: All For One and Argo 2 for All!"
*** Checking out Kingfisher at "1.6.0"
*** xcodebuild output can be found in /var/folders/ph/q91_nyh55v3_63cp6p6mnvx00000gn/T/carthage-xcodebuild.Wq72O1.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "CleanroomASL-iOS" in CleanroomASL.xcodeproj
*** Building scheme "Kingfisher" in Kingfisher.xcworkspace
*** Building scheme "CleanroomLogger-iOS" in CleanroomLogger.xcodeproj

building成功後,cathange會build出所有平台的frameworks,我們只需要用到iOS的,buliding出的fremework在 PROJECT_HOME/Carthage/Build/iOS/Xxx.framework, framework如果還有依賴其他的fremeworks也會一併的building出來, 可能會出多一些不在預期內的 frameworks,但這些都是要用到的

├── Build
│   ├── Mac
│   │   └── Argo.framework
│   └── iOS
│       ├── Alamofire.framework
│       ├── Alamofire.framework.dSYM
│       ├── Argo.framework
│       ├── CleanroomASL.framework
│       ├── CleanroomASL.framework.dSYM
│       ├── CleanroomLogger.framework
│       ├── CleanroomLogger.framework.dSYM
│       ├── Kingfisher.framework
│       └── Kingfisher.framework.dSYM
└── Checkouts
    ├── Alamofire
    ├── CleanroomASL
    ├── CleanroomLogger
    └── Kingfisher

將build出來的freamwork加入xcode的build target

  1. .xcodeproj (藍色的小icon) -> “application targets” -> “General” tab
  2. PROJECT_HOME/Carthage/Build/iOS/下所有副檔名為.framework 都選取拉到 “Linked Frameworks and Libraries”

application targets為是專案名稱

加入 run script

  1. “application targets” -> “Build Phases” tab 按 “+” 的icon,選擇”New Run Script Phase”加入新的run script
  2. 加入shell參數 /usr/local/bin/carthage copy-frameworks
  3. 加入所有的$(SRCROOT)/Carthage/Build/iOS/xxx.framework

讓unit test可以使用加入的freamework

上面做的操作,都是在 “application targets” 上操作的,也就是只有 product code能用這些freamworks, 如果要在test code也能用,那必須也把這些 frameworks 加到 test build 的link path

  1. 一樣選 .xcodeproj (藍色的小icon)

  2. 這次換選 test target,會是你的’專案名稱 + Tests’

  3. 選 “Build Phases” tab
  4. PROJECT_HOME/Carthage/Build/iOS/下所有副檔名為.framework 都選取拉到 “Linked Frameworks and Libraries”