MQZHot / DaisyNet

Alamofire与Cache封装 , 更容易存储请求数据
MIT License
379 stars 65 forks source link

如何区分请求类型get、post.... ? #1

Closed Baiyongyu closed 6 years ago

Baiyongyu commented 6 years ago

刚刚学习Swift,很多语法还不是很明白,不知道楼主这个框架在发起请求的时候是如何区分请求类型的。

MQZHot commented 6 years ago

DaisyNet.request(url, params: params) request方法包含很多默认参数,具体使用跟Alamofire是一致的

func request( _ url: String, method: HTTPMethod = .get, params: Parameters? = nil, encoding: ParameterEncoding = URLEncoding.default, headers: HTTPHeaders? = nil)

Baiyongyu commented 6 years ago

DaisyNet.request(url, params: params).cache(true).responseCacheAndString { value in switch value.result { case .success(let string):

            if value.isCacheData {
                self.cacheTextView.text = string
            } else {
                self.textView.text = string
            }

        case .failure(let error):
            print(error)
        }
    }

那你写的这里是怎么判断的

MQZHot commented 6 years ago

DaisyNet.request(url, params: params) DaisyNet.request(url, method: .post, params: params) method参数省略默认get,修改请求类型的话改变method参数

Baiyongyu commented 6 years ago

Thanks