LoginSignup
81
77

More than 5 years have passed since last update.

[Swift] CocoaPodsの代わりにCarthageを使って、RealmやReactiveCocoaなどを入れてみた。

Last updated at Posted at 2015-07-10

CocoaPodsが重々しかったので、Carthageを使ってみた。
CocoaPodsとCarthageの違いについてはこちらを参照。

Install

  1. ダウロード
    • まずはここから最新版の(別に最新版でなくてもいいですが)pkgファイルを落としてくる。
    • homebrewなら
brew update
brew install carthage
  1. 落としたファイルをMac上で展開して、インストールする。
  2. すると、carthageコマンドが使えるようになる。

Carthage でライブラリを管理

コマンド

$ carthage
Available commands:
   archive           Archives a built framework into a zip that Carthage can use
   bootstrap         Check out and build the project's dependencies
   build             Build the project's dependencies
   checkout          Check out the project's dependencies
   copy-frameworks   In a Run Script build phase, copies each framework specified by a SCRIPT_INPUT_FILE environment variable into the built app bundle
   fetch             Clones or fetches a Git repository ahead of time
   help              Display general or command-specific help
   update            Update and rebuild the project's dependencies
   version           Display the current version of Carthage

バージョン

$ carthage version
0.7.5

Cartfile

試しにReactiveCocoaをインストール。

$ vi Cartfile
----
github "ReactiveCocoa/ReactiveCocoa" "swift-development"
$ carthage update --platform iOS
*** Cloning ReactiveCocoa
*** Cloning Result
*** Cloning Box
*** Checking out Result at "0.4.4"
*** Downloading Box at "1.2.2"
*** Checking out ReactiveCocoa at "72854649533c4df644a896df7070a0cb835f8d60"
*** xcodebuild output can be found in /var/folders/kv/8m4bhynx3fd25w4pbpnl24h80000gn/T/carthage-xcodebuild.FFPdHc.log
*** Building scheme "Result-iOS" in Result.xcworkspace
2015-07-10 13:47:50.815 xcodebuild[26076:218196] [MT] PluginLoading: Required plug-in compatibility UUID 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/RealmPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2015-07-10 13:47:57.685 xcodebuild[26148:218543] [MT] PluginLoading: Required plug-in compatibility UUID 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/RealmPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs
*** Building scheme "ReactiveCocoa iOS" in ReactiveCocoa.xcworkspace
2015-07-10 13:48:07.599 xcodebuild[26262:219042] [MT] PluginLoading: Required plug-in compatibility UUID 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/RealmPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2015-07-10 13:48:54.356 xcodebuild[26923:221180] [MT] PluginLoading: Required plug-in compatibility UUID 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/RealmPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs

frameworkとして以下のディレクトリに入るらしい。

$ ll ./Carthage/Build/iOS/
total 0
drwxr-xr-x  5 hoge  staff  170  7 10 13:49 ./
drwxr-xr-x  4 hoge  staff  136  7 10 13:47 ../
drwxr-xr-x  7 hoge  staff  238  5  6 07:35 Box.framework/
drwxr-xr-x  7 hoge  staff  238  7 10 13:49 ReactiveCocoa.framework/
drwxr-xr-x  7 hoge  staff  238  7 10 13:48 Result.framework/

git cloneしたものがいかにあるよう。

$ ll ./Carthage/Checkouts/
total 0
drwxr-xr-x   4 hoge  staff  136  7 10 13:47 ./
drwxr-xr-x   4 hoge  staff  136  7 10 13:47 ../
drwxr-xr-x  20 hoge  staff  680  7 10 13:47 ReactiveCocoa/
drwxr-xr-x  13 hoge  staff  442  7 10 13:47 Result/

差分は以下の通り。

$ st
On branch carthage
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    Cartfile
    Cartfile.resolved
    Carthage/

使います

Finderあたりから、インストールしたframeworkをGeneral > Linked Frameworks and Binariesに入れる。

Screen_Shot_2015-07-10_at_14_24_53.png

するとにも追加されます。

これでやっと、import出来る様になります。

import ReactiveCocoa

他のライブラリも入れてみる

Cartfile
github "ReactiveCocoa/ReactiveCocoa" "swift-development"
github "SwiftyJSON/SwiftyJSON" >= 2.2.0
github "Alamofire/Alamofire" >= 1.2
github "realm/realm-cocoa"
$ carthage update --platform iOS

Scriptの追加

  • アプリのターゲットの “Build Phases” の “+” ボタンをクリックし、以下のような “New Run Script Phase” を追加します。
/usr/local/bin/carthage copy-frameworks

この時 “Input Files” にはフレームワークのパスを指定します。

$(SRCROOT)/Carthage/Build/iOS/AlamoFire.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftyJSON.framework
$(SRCROOT)/Carthage/Build/iOS/Realm.framework 
$(SRCROOT)/Carthage/Build/iOS/RealmSwift.framework

Screen Shot 2015-07-10 at 14.30.51.png

References

81
77
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
81
77