目录
目录README.md

MGENetwork

Build & Test GitHub tag (latest SemVer) License

Description

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.

  1. Add this to your file import statements
import MGENetwork
  1. Instantiate a NetworkClient masking it with the NetworkProvider protocol
let networkClient: NetworkProvider = NetworkClient()
  1. Declare a response type conforming to Decodable
struct MyResponse: Decodable {
  let id: Int
  let message: String
}
  1. 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")
  1. 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)
  }
}

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.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号