1.WMGetApiManager(get请求)
import UIKit import Moya enum WMGetApiManager { //获取配置 case appConfig //获取app信息 case getAppInfo(phone: String) } extension WMGetApiManager: TargetType { var baseURL: URL { switch self { case .appConfig, .getAppInfo: return URL(string: "https://www.baidu.com/1")! } } var headers: [String : String]? { let header = [ "Content-Type": "application/x-www-form-urlencoded" ] return header } var method: Moya.Method { return .get } var path: String { switch self { case .appConfig: return "/getappconfig" case let .getAppInfo(phone): return "/getAppInfo?phone=\(phone)" } } var task: Moya.Task { let params = [String: Any]() return .requestParameters(parameters: params, encoding: URLEncoding.default) } }
2.调用
func netWorkRequestAppInfo(phone: String) { let api = WMGetApiManager.getAppInfo(phone: phone) VToast.showLoading() Network.request(api, dataType: Model.self, showErrorMsg: true).do(onSuccess: { [weak self] (data) in //返回数据 }, one rror: { error in VToast.showToast(msg: (error as? APIError)?.message) }, onDispose: { VToast.hideLoading() }).subscribe().disposed(by: disposeBag) }
标签:case,getAppInfo,return,String,框架,网络,phone,var,swift From: https://www.cnblogs.com/wm941142146/p/17874662.html