GenericNetworking
特性
- GET / POST方法
- 上传数据
示例
要运行示例项目,请克隆存储库,然后从示例目录运行pod install
。
class GithubSDK {
public static func getGists(completion: @escaping GenericNetworkingCompletion<[Gist]>) {
// response is array of objects
GenericNetworking.requestJSON(baseURLString: "https://api.github.com", path: "/gists", method: .get, parameters: nil, headers: nil, completion: completion);
}
public static func getGistDetail(_ gistId: String, completion: @escaping GenericNetworkingCompletion<Gist>) {
// response is an object
let URLString = "https://api.github.com/gists/" + gistId
GenericNetworking.getJSON(URLString: URLString, completion: completion)
}
}
这里您可以像以下这样调用GithubSDK
GithubSDK.getGists { (response) in
switch response {
case .success(let gists):
print(gists.count)
for gist in gists {
print("gist id:\(gist.identifider)")
}
case .error(let error):
print(error)
}
}
需求
- Swift 4.0
- Alamofire
安装
GenericNetworking可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod 'GenericNetworking'
作者
alexiscn, [email protected]
许可协议
GenericNetworking可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。