一、手動導入
1, 官網下載 Alamofire

2, 解壓下載的文件 放入工程的頂層目錄下

3, 打開工程 Add Files

4, 選中項目 TARGETS > General > Embedded Binaries > +(添加) 完成。 注意選擇對應的framework,我們這里選擇frameworkiOS

5, 檢測是否添加成功,首先檢測項目部署版本,使用Alamofire項目 Deployment Target最低為8.0,然后運行下面的代碼,調試區輸出內容。至此,添加成功

Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
二、CocoaPods導入
CocoasPods是 Cocoa 工程的依賴管理工具,安裝Alamofire需要CocoasPods最低版本為0.39.0,用下面的命令查看pod版本,版本太低的同學需要先升級
pod --version
1, 進入工程目錄,創建Podfile文件,文件內容如下
<Your Target Name> 替換成工程對應的名字
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'Alamofire', '~> 3.4'
end
2, 然后終端切換到Podfile所在目錄 輸入命令
pod install
上面兩步已經完成導入工作了,在需要使用Alamofire的地方直接導入即可
參考資料(戳這里):
> https://github.com/Alamofire/Alamofire#installation
