Code Monkey home page Code Monkey logo

basiscomponent's Introduction

BasisComponent

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Description

1、常用的扩展,工具类等

2、为部分系统控件添加Reactive扩展

3、基于CTMediator的Swift版本,加以改造

4、为一些三方控件添加Reactive扩展,Refresh,Hud 等

5、将Alamofire请求转换为Observable,并带自动解析

Mediator

路由的基本实现:
/// 路由调用组件库
/// - Parameters:
///   - module: 模块名
///   - functionKey: 方法键
///   - params: 要传递的参数
///   - result: 回调
/// - Returns: void
public func perform(_ module: String, functionKey: String, params: [String:Any],result:MediatorResult = nil) -> () {
    let `class`: AnyClass? = NSClassFromString(module + "." + "Target")
    guard let anyclass = `class` as? NSObject.Type else {
        return
    }
    let object = anyclass.init()
    let mirror = Mirror.init(reflecting: object)
    print("Target:\(module).\(mirror.subjectType)")
    for (name, value) in (mirror.children) {
        if name != "functions" {
            break
        }
        if let function = value as? Dictionary<String,MediatorJsonAndResult> {
            function[functionKey]?(params,result)
            return
        }
    }
}
    
用例Target:
class Target: NSObject {
    static let `default` = Target()
    let functions : [String : Mediator.MediatorJsonAndResult] = [
        "test":{json,result in
            Target.default.test(params: json, result: result)
        }
    ]
    func test(params:Mediator.MediatorJson,result:Mediator.MediatorResult) -> () {
        print("targt 执行")
        result?("complete")
    }
}

路由调用测试:
Mediator.default.perform("BasisComponent", functionKey: "test", params: [:]) { result in
   print(result ?? "Complete")
}

Net

class User: HandyJSON {
    var name : String?
    required init() {}
}

let api = NetToolClient()
api.path = "url"
api.parameters = ["a":1]

//example1 : 普通的网络请求(返回Json)
api.request { (result:Result<JsonType>) in
    if result.isSuccess {
        print(result.value?["name"] ?? "")
    }
    else{
        print(result.error!)
    }
}

//example2 : 普通的网络请求(返回User)
api.request { (result:Result<User>) in
    if result.isSuccess {
        print(result.value?.name ?? "")
    }
    else{
        print(result.error!)
    }
}

//example3: RX网络请求(返回 Observeable<User>)
let observable = api.rx.request() as Observable<User>
observable.subscribe(onNext: { user in
    print("\(user.name ?? "")")
}).disposed(by: disposeBag)

Requirements

Installation

BasisComponent is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BasisComponent'

Author

U7426, [email protected]

License

BasisComponent is available under the MIT license. See the LICENSE file for more info.

basiscomponent's People

Contributors

u7426 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.