使用CocoaPods
CocoaPods使用之前我們先在Xcode建立一個專案
並按下右鍵選擇New File...
或是在選單上面的File
->New
->File...
建立個Empty
空白檔案
名稱命名為Podfile
Podfile不需要跟著一起編譯,它只是要讓CocoaPods讀取的設定檔,所以,我們將Targets
上面有勾選的取消
檔案建立完成,直接在Xcode上編輯
CocoaPods管理每個專案的Pod時,它利用專案下的Podfile做為設定檔來管理及更新Pod的內容,當然還還有iOS的環境。
接下來,我們繼續前面的結果當例子,剛搜尋結果內容:
-> AFNetworking (2.0.3) A delightful iOS and OS X networking framework. pod 'AFNetworking', '~> 2.0.3' - Homepage: https://github.com/AFNetworking/AFNetworking - Source: https://github.com/AFNetworking/AFNetworking.git - Versions: 2.0.3, 2.0.2, 2.0.1, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 2.0.0, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0RC3, 1.0RC2, 1.0RC1, 1.0.1, 1.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1, 0.10.1, 0.10.0 [master repo] - Sub specs: - AFNetworking/Serialization (2.0.3) - AFNetworking/Security (2.0.3) - AFNetworking/Reachability (2.0.3) - AFNetworking/NSURLConnection (2.0.3) - AFNetworking/NSURLSession (2.0.3) - AFNetworking/UIKit (2.0.3)`
看到第三行:
pod 'AFNetworking', '~> 2.0.3'`
這就是使用Libray的方式。
我們將它加入Podfile
platform :ios, '7.0' pod 'AFNetworking', '~> 2.0.3'`
存檔完成後先用Finder
到專案的目錄下看一下結構並說明一下:
建立Podfile
檔案必需與.xcodeproj
放在同一層目錄下,CocoaPods建立的過程需要它的輔助來產生工作檔(xcworkspace)。