我们都知道AFNetworking在国内多牛X,这哥们又写了swift的第三方请求 Alamofire 这到底怎么使用呢
我们可以通过GitHub上下载东西
当然我们也可以使用 cocoaPods
1,打开终端 2,cd 把我们的工程拖进去 回车 3,vim podfile (创建来了podfile文本) 4,在文本里面target '你的工程名' do pod 'Alamofire' end
4,pod install 当配置完成时 打开白色文件
我们知道在swift里面不用输入头文件 但是我们的第三方库还是要 import 的
Alamofire.request("你的URL网址", method: .get(或者post), parameters:(参数), encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
if(response.error == nil){
print("请求成功")
var dict:NSDictionary = response.result.value as! NSDictionary
let dic:NSDictionary = dict.object(forKey: "data") as! NSDictionary
//请求完了 别忘了刷新表格 创建一个全局变量数组 我们想要什么就把response里面打印就一层一层的往下拆数据 最好先把请求好的数据存入字典
}else{
LLog("请求失败\(String(describing: response.error))")
}
}