PocketNet
使用Swift 5.0编写的优雅网络抽象层,我们提供了与Alamofire的集成。
要求
- iOS 8.0+
安装
CocoaPods
CocoaPods是一款适用于Cocoa项目的依赖关系管理器。您可以使用以下命令安装它
$ gem install cocoapods
要构建PocketNet 2.4.0,需要CocoaPods 1.1+
要使用CocoaPods将PocketNet集成到您的Xcode项目中,请在您的Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
pod 'PocketNet'
end
然后,运行以下命令
$ pod install
使用方法
import PocketNet
let net: PocketNet = PocketNetAlamofire() /*or for SSL Pinning*/ PocketNetAlamofire(pinningSSLCertURL: Bundle.main.url(forResource: "cert", withExtension: "crt"), domain: "urlDomain")
let netSupport = NetSupport(net: net)
let request = NetRequest.Builder()
.method(.post)
.url("url")
.requestHeader([:])
.parameterEncoding(.json)
.body(params: "")
.shouldCache(false)
.build()
netSupport.netJsonMappableRequest(request, completion: {(result: Result<DecodableObject, Error>) in
switch result {
case .success(let decodableObject):
/// do something with decodableObject
case .failure(let error):
/// do something with error
}
})
netSupport.netArrayJsonMappableRequest(request, completion: {(result: Result<[DecodableObject], Error>) in
switch result {
case .success(let decodableObject):
/// do something with decodableObject
case .failure(let error):
/// do something with error
}
})
作者
特别感谢
在本项目中使用的库
许可证
Net可用在MIT许可证下。更多信息请查阅LICENSE文件。