swift - how to pass a nil value for one of the parameter in alamofire Post request -
i pass nil value i.e., optional 1 of parameter value. , must proceed nil value in alamofire post request .it helpful if tell me how proceed next?
let image: uiimage = uiimage() let imagedata = uiimagepngrepresentation(image) let base64string = imagedata?.base64encodedstringwithoptions(.encoding64characterlinelength) let parameters = [ "first_name": "xxxxx", "email" : "1234@gmail.com", "password" : "password", "profile_picture" : base64string] alamofire.request(.post, "http://abc/public/user/register", parameters: parameters, encoding: .json, headers: nil) .progress { byteswritten, totalbyteswritten, totalbytesexpectedtowrite in print(totalbyteswritten) // closure not called on main queue performance // reasons. update ui, dispatch main queue. dispatch_async(dispatch_get_main_queue()) { print("total bytes written on main queue: \(totalbyteswritten)") } } .responsejson { response in debugprint(response) }
the response should gets succeeded if profile_pictures empty. know can done optional chaining don't know how proceed!!
by passing nil or uninitialized optional parameter server optional
you can pass nsnull() dictionary
try this, like
var params = ["parama","valuea"] if imagebase64 == nil { parms["image"] = nsnull()} else { params["image"] = imagebase64 }
swiftyjson handle null nsnull
also there reference here null / nil in swift language
Comments
Post a Comment