A swifty network layer powered by Operations and OperationQueues.
Example
To run the example project, clone this repo, and open MGENetwork.xcworkspace from the iOS Example directory.
Requirements
Requires iOS 9.0.
Installation
Add this to your project using Swift Package Manager.
In Xcode that is simply: ‘File > Swift Packages > Add Package Dependency…’, paste https://martin-e91.github.io/swift-mge-network/ and you’re done.
Usage
The clean way to use this is to use the protocol NetworkProvider as a gateway for all the network related tasks.
Add this to your file import statements
import MGENetwork
Instantiate a NetworkClient masking it with the NetworkProvider protocol
let networkClient: NetworkProvider = NetworkClient()
Declare a response type conforming to Decodable
struct MyResponse: Decodable {
let id: Int
let message: String
}
Declare a Requestable conforming type, or use the predefined NetworkRequest from the module, in order to describe an HTTP Request
let request = NetworkRequest<MyResponse>(method: .get, endpoint: "www.domain.com")
Pass the request instance as argument to the perform method of the NetworkProvider like that:
networkClient.perform(request) { [weak self] result in
switch result {
case .failure(let error):
self?.handle(error)
case .success(let data):
self?.updateUI(with: data)
}
}
MGENetwork
Description
A swifty network layer powered by
Operation
s andOperationQueues
.Example
To run the example project, clone this repo, and open MGENetwork.xcworkspace from the iOS Example directory.
Requirements
Requires iOS 9.0.
Installation
Add this to your project using Swift Package Manager. In Xcode that is simply: ‘File > Swift Packages > Add Package Dependency…’, paste
https://martin-e91.github.io/swift-mge-network/
and you’re done.Usage
The clean way to use this is to use the protocol
NetworkProvider
as a gateway for all the network related tasks.import
statementsNetworkClient
masking it with theNetworkProvider
protocolDecodable
Requestable
conforming type, or use the predefinedNetworkRequest
from the module, in order to describe an HTTP Requestrequest
instance as argument to theperform
method of theNetworkProvider
like that:Documentation
You can find the complete documentation here
Contributing
Feel free to give your contribution or open a new issue! 😄
Author
Martin Essuman
License
MGENetwork is available under the MIT license. See the LICENSE file for more information.