evermeer / EVReflection

Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Other
966 stars 119 forks source link

Moya map doesn’t work #304

Closed AdieOlami closed 5 years ago

AdieOlami commented 5 years ago

I’m trying out with rx but there seems to be nothing like .map(toArray:....)

func getNutritionHistoryData(date: Date) -> Observable<[[NutritionHistory]]> {

    return self.provider.request(.nutritionHistory(date: Date))
        .map(toArray: [NutritionHistory]) 
}

What could be the issue please

evermeer commented 5 years ago

Did you add the pod spec pod 'EVReflection/MoyaRxSwift' And did you add import EVReflection at the top of that file?

AdieOlami commented 5 years ago

Yes I did. I only say Rmap

evermeer commented 5 years ago

Ah, true, there were conflicts when using the same .map function between reactive and not. Therefore I had to rename the reactive map to Rmap. Please have a look at the MoyaRxSwiftTests unit test file to see it in action. In your case you should use

        provider.request(.nutritionHistory(date: Date)) { (result) in
            switch result {
            case .success(let response):
                do {
                    let parsed = try response.RmapArray(to: NutritionHistory.self)
evermeer commented 5 years ago

Just reopen this if it's still an issue