swift - Send json body by alamofire

0

I'm on my first project in Swift, and I need to send a RequestBody to POST through Alamofire.

This is an example of JSON that I need to send:

{
"user":{
    "email":"[email protected]"
 }
}

And I have my Class User .

 func toDictionary() -> [String:Any]
{
    var dictionary = [String:Any]()

    if email != nil{
        dictionary["email"] = email
    }

    return dictionary
}

I'm using SwiftyJSON to do parse. My question is basically how do I turn my object into that JSON framework I need and send through the Alamofire as POST.

    
asked by anonymous 14.09.2017 / 16:47

1 answer

0

Alamofire allows you to send a dictionary as parameters of a POST:

Alamofire.request(.POST, "http://myserver.com", parameters: User.toDictionary(), encoding: .JSON)
.responseJSON { request, response, JSON, error in
    print(response)
    print(JSON)
    print(error)
}
    
01.10.2017 / 15:32