Latest 0.1.1
Homepage https://github.com/seongbrave/NetWorkCore
License MIT
Platforms ios 8.0
Dependencies ModelProtocol, RxSwift, RxCocoa, Alamofire, Result
Frameworks UIKit
Authors

Alamofire的基础上封装了一套网络请求,并且实现数据解析的工具库,配合RxSwift使用起来非常方便

使用要求

  • Xcode 9.0+

安装

CocoaPods

pod 'NetWorkCore', '~> 0.0.1'

具体使用

1. 发起普通的网络请求

  NetWorkAPI.sharedInstance.requestSwiftyJSONReg(Api.topics) { (result) in
            switch result {
            case .success(let repos):
                print(repos)
            case .failure(let error):
                print(error)
            }
        }

2. 流式网络请求

 Observable.just("")
            .map { _ in Api.topics}
            .emeRequestApiForJson().subscribe(onNext: {(result) in
                switch result {
                case .success(let data):
                    print(data)
                case .failure(let error):
                    print(error)
                }
            })
            .disposed(by: disposeBag)

3. 约定好返回数据状态

在发起网络请求之前需要配置下

//正确码 即:successCode 为1 的时候才会解析dataKey字段的值得
NetWorkCore.successCode = 1
// 获取successCode的建是对应的success
NetWorkCore.statusKey = "success"
// 获取data中的数据
NetWorkCore.dataKey = "data"

发起网络请求

 Observable.just("")
            .map { _ in Api.topics}
            .emeRequestApiForArray(TopicsModel.self)
            .subscribe(onNext: {(result) in
                switch result {
                case .success(let data):
                    print(data)
                case .failure(let error):
                    print(error)
                }
            })
            .disposed(by: disposeBag)

4. 发起请求然后界面直接得到的是 model

   func request3()  {
        Observable.just("")
            .map { _ in Api.topics}
            .emeRequestApiForArray(TopicsModel.self)
            .subscribe(onNext: {(result) in
                switch result {
                case .success(let data):
                    print(data)
                case .failure(let error):
                    print(error)
                }
            })
            .disposed(by: disposeBag)
    }

Latest podspec

{
    "name": "NetWorkCore",
    "version": "0.1.1",
    "summary": "RxSwiftu5c01u88c5u7f51u7edcu8bf7u6c42",
    "description": "TODO: RxSwiftu5c01u88c5u7edcu8bf7u6c42u5c01uff0c u5305u542bu4e86u7f51u7edcu8bf7u6c42uff0cu6570u636eu89e3u6790u7b49...",
    "homepage": "https://github.com/seongbrave/NetWorkCore",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "seongbrave": "[email protected]"
    },
    "source": {
        "git": "https://github.com/seongbrave/NetWorkCore.git",
        "tag": "0.1.1"
    },
    "social_media_url": "http://seongbrave.github.io/",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "NetWorkCore/Classes/**/*.{swift}",
    "frameworks": "UIKit",
    "dependencies": {
        "ModelProtocol": [
            "~> 0.1.0"
        ],
        "RxSwift": [
            "~> 4.4.0"
        ],
        "RxCocoa": [
            "~> 4.4.0"
        ],
        "Alamofire": [
            "~> 4.7.3"
        ],
        "Result": [
            "~> 4.0.0"
        ]
    }
}

Pin It on Pinterest

Share This