tuan188 / MGCleanArchitecture

Clean Architecture with RxSwift & MVVM - Templates and Solutions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not map the response is single array without key

trantran8 opened this issue · comments

I am getting list github's user with api: https://api.github.com/users, but can't map the response.
I tried debugging and found that json is nil

image

My Output:

final class GetUserListOutput: APIOutput, Equatable {
    private(set) var users: [User]?

    override func mapping(map: Map) {
        super.mapping(map: map)
        users <- map[""]
    }
}

My Model:

struct User {
    var id = 0
    var login = ""
    var avatarURLString = ""
}

extension User: Mappable {

    init?(map: Map) {
        self.init()
    }

    mutating func mapping(map: Map) {
        id <- map["id"]
        login <- map["login"]
        avatarURLString <- map["avatar_url"]
    }
}

Thanks for any help.

@trantran8
You don't need to use GetUserListOutput

    func getUserList(_ input: GetUserListInput) -> Observable<[User]> {
        return request(input)
    }

Usage:

API.shared.getUserList(API.GetUserListInput())
            .subscribe(onNext: { users in
                print(users)
            })
            .disposed(by: disposeBag)

I dit it, thank you.