alamofire

Alamofire 5 GET 请求,解析返回JSON

假如想象 提交于 2020-08-16 14:04:18
Alamofire 5 GET 请求,解析返回JSON struct Login: Encodable { let userCode: String let password: String } let login = Login(userCode: userCode!, password: password!) AF.request(serviceUrl+"/pub/login/submit", method: .get, parameters: login //encoder: JSONParameterEncoder.default ).responseJSON { response in //print(response.result) switch response.result { case .success(let JSON): print("Success with JSON: \(JSON)") let dict = JSON as! Dictionary<String,AnyObject> let code = dict["code"] as! String let data = dict["data"] as! String let message = dict["message"] as! String print(message) case

swift对Moya的一些功能封装

柔情痞子 提交于 2020-08-16 07:11:07
项目开发中的接口比较多,在使用moya时会使用多个类,为避免一些代买的重复书写,做了一些封装处理,网络使用Alamofire,数据解析使用Moya-ObjectMapper 首先是对返回数据统一处理的模型 import ObjectMapper import Moya class ResponseModel: NSObject,Mappable { /// 返回码 var code:Int = 0 /// 信息 var message:String = "" /// 数据 var data:Any? override init() {super.init()} init(_ code: Int, message:String, data:Any? = nil) { self.code = code self.message = message self.data = data } class func success(_ data:Any) ->ResponseModel{ return ResponseModel(200, message: "SUCCESS", data: data) } class func faild(_ message:String? = "FAILD") ->ResponseModel{ return ResponseModel(400, message

Error installing Alamofire in Mac Using Pod

依然范特西╮ 提交于 2020-08-11 03:58:23
问题 I am trying to install Alamofire for iOS app development using pod. My podfile looks like below: # Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'AlamoFireBackgroundTask' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! pod 'Alamofire' # Pods for AlamoFireBackgroundTask end when I run pod install I get the following error message: [!] Error installing Alamofire [!] /usr/bin/git

Error installing Alamofire in Mac Using Pod

允我心安 提交于 2020-08-11 03:58:07
问题 I am trying to install Alamofire for iOS app development using pod. My podfile looks like below: # Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'AlamoFireBackgroundTask' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! pod 'Alamofire' # Pods for AlamoFireBackgroundTask end when I run pod install I get the following error message: [!] Error installing Alamofire [!] /usr/bin/git

How to use Moya to download file

非 Y 不嫁゛ 提交于 2020-08-03 03:32:28
问题 Usual I use Alamofire & Moya/RxSwift & ObjectMapper to analysis object But now add a demand. My app need download file. I have use Alamofire.download(urlString, to: destination) Temporary solved the problem but It's not elegant. I want use Moya to Maintain the same network layer. Can you show a Download Moya"s "TargetType" 回答1: to use Moya to download files, the key thing is override ` var task:Task{ switch self { case .download: return .download(DownloadType.request

How to access value of __nssingleobjectarrayi in the following code

ぐ巨炮叔叔 提交于 2020-07-22 06:47:30
问题 I parsed a json and got a JSON Dictionary. { data = ( { bio = "<null>"; bookmarked = 35; id = 22; "last_seen" = { date = "2017-03-30 14:00:01"; timezone = "Asia/Kolkata"; "timezone_type" = 3; }; name = "Alex"; username = "Alex"; } );} I am trying to access username and date. I tried it doing let name = userData.value(forKeyPath: "data.username") print(username) By printing this, I am getting a __NSSingleObjectArrayI with the username. Optional(<__NSSingleObjectArrayI 0x6080000120b0>( Alex ) )