Blazej SLEBODA
Blazej SLEBODA

Reputation: 9915

RxAlamofire: Ambiguous reference to member 'json(_:_:parameters:encoding:headers:)'

When I try to compile the code below, I get an error:

Ambiguous reference to member 'json(::parameters:encoding:headers:)'

The code was copied and pasted from a RxAlamofire Github repository page

import RxSwift
import RxAlamofire

class CurrencyRest {

        static func getJson() {

            let stringURL = "https://api.fixer.io/latest"

            // MARK: NSURLSession simple and fast
            let session = URLSession.init()

            _ = session.rx.json(.get, stringURL)
                .observeOn(MainScheduler.instance)
                .subscribe { print($0) }
        }

}

Upvotes: 0

Views: 166

Answers (1)

zuchie
zuchie

Reputation: 78

To fix the error, session.rx.json(url:) is the way to go, it's from RxCocoa, although for RxAlamofire, you don't have to use URLSession rx extension, instead, use json(::parameters:encoding:headers:), e.g. json(.get, stringURL), which returns an Observable<Any> that you can use as JSON.

Upvotes: 0

Related Questions