Moya: I want wrap Moya into function, but no work.

Created on 2 Nov 2017  路  3Comments  路  Source: Moya/Moya

i try like this

class Model<T: TargetType>: NSObject {

    func request<H: HandyJSON>(_ type: T, _ model: H.Type) -> Observable<H> {

        let mp = MoyaProvider<T>()

        return  mp
                .rx.request(type)
                .asObservable()
                .map(model)

    }

}
class FirstViewModel: BaseViewModel<API>  {

    override func initialize() {

    }

}

BaseViewModel has a instance of Model

then i call it.

let vm = (self.viewModel as! FirstViewModel)

            vm
            .model
            .request(.Show, FirstModel.self)
            .bind { (model) in
                print(model)
            }
            .disposed(by: self.rx.disposeBag)

but it didn't work.

question

Most helpful comment

you're disposing your provider. Check out the documentation at https://github.com/Moya/Moya/pull/1386

All 3 comments

you're disposing your provider. Check out the documentation at https://github.com/Moya/Moya/pull/1386

It works as usual!

@AndrewSB thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JoeFerrucci picture JoeFerrucci  路  3Comments

dimpiax picture dimpiax  路  3Comments

GurpalRajput picture GurpalRajput  路  3Comments

mwawrusch picture mwawrusch  路  3Comments

hjzCy picture hjzCy  路  3Comments