Swift网络库Alamofire的导入
一、手动导入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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |