I would like to pass a nil value i.e., optional to one of the parameter value. And it must proceed with the nil value in the Alamofire Post request .It woul
After a very thorough research, I found out it can be done easily through optional chaining and type casting.
The first step it to divide the parameters by type casting it to string and Image and check for the availability of String value and Image value.
let parameters: [String : AnyObject? ] = [
"first_name": "XXXXX",
"email" : "1234@gmail.com",
"password" : "password",
"profile_pic" : UIImage(named: "logo")]
Do it like this in the request method
for (key, value) in parameters {
if let value1 = value as? String {
multipartFormData.appendBodyPart(data: value1.dataUsingEncoding(NSUTF8StringEncoding)!, name: key)
}
if let value1 = value as? UIImage {
let imageData = UIImageJPEGRepresentation(value1, 1)
multipartFormData.appendBodyPart(data: imageData!, name: key, fileName: "logo.png" , mimeType: "image/png")
}
You don't have to split the parameters into two, one for the string values and other for the image and also it is unnecessary to convert the image to string. Hope this solution helps!!