AlamofireObjectMapper Cannot call 'responseObject' with a list of arguments of type '((User ?, NSError?) & # 8594; _)'

I use the AlamofireObjectMapper structure in swift and, as said at https://github.com/tristanhimmelman/AlamofireObjectMapper , I want to use "responseObject" with a custom class, but it doesn’t "t:

the code:

let URL = "http://37.187.145.241:8080/MasterMarket/api/users-maxou/2"
        Alamofire.request(.GET, URL, parameters: nil)
            .responseObject { (response: User?, error: NSError?) in
                println(response?.company?.nameCompany)
                println(response?.lastNameUser)
        }

My user class User:

class User : Mappable {

var idUser : Int?
var firstNameUser : String?
var lastNameUser : String?
var phoneNumberUser : String?
var parent : User?
var removeUser : Bool?
var managerRightsUser : Bool?

var company : Company?
var genderType : GenderType?
var userType : UserType?
var deposit : Deposit?

var createdUser : String?
var modifiedUser : String?

init() {}

required init?(_ map: Map) {
    mapping(map)
}

func mapping(decoder: Map) {
    idUser <- decoder["idUser"]
    firstNameUser <- decoder["firstNameUser"]
    lastNameUser <- decoder["lastNameUser"]
    phoneNumberUser <- decoder["phoneNumberUser"]
    removeUser <- decoder["removeUser"]
    managerRightsUser <- decoder["managerRightsUser"]

    parent <- decoder["parent"]
    company <- decoder["company"]

}

and error:

Cannot invoke 'responseObject' with an argument list of type '((User?, NSError?) -> _)'
+4
source share
2 answers

I had the same problem, in fact the error was not in the responseObject () method, but in the request ().

The solution was to specify the type (String) of my parameter array for the request method. You have no parameters, maybe add: String for your URL?

+2

2.1. :

    Alamofire.request(.GET, URL, parameters: nil)
        .responseObject({ (response: Response< User, NSError>) -> Void in
            if response.result.isSuccess {
                print(response.result.value)
            }
        })

!

0

Source: https://habr.com/ru/post/1598181/


All Articles