title: completion handler at alamofire multipart upload request
body: <p>I have an issue with my func in swift to get the data (JSON) back. I know its the completion handling but I am struggling so maybe someone can help.</p>
  
  <p>The code below shows my function. The API needs the json as string in a field. The request itself works > the print(post) shows the correct data. But I don't get it out that function.
  (I use Alamofire, SwiftyJSON, swift2.2 and xcode 7.3)</p>
  
  <pre><code>class func searchCities(jsonStr: String) -&gt; JSON {
  
      let oEndpoint = "https://api.domain.com/api/1.0/"
      guard let url = NSURL(string: oEndpoint) else {
          print("error url")
          return nil
      }
  
      // let parameters : [String: String] = ["one":"some param", "two":"some other param"]
      var result: JSON = JSON("")
  
      Alamofire.upload(.POST,
                       url,
                       multipartFormData: { multipartFormData in
                          multipartFormData.appendBodyPart(data: jsonStr.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"data")
                          // parameters if needed  
                          // multipartFormData.appendBodyPart(data: value, name: key)
                      },
                       encodingCompletion: { encodingResult in
                          switch encodingResult {
                          case .Success(let upload, _, _):
                              upload.responseJSON{ response in
                                  guard response.result.error == nil else {
                                      print("error response")
                                      print(response.result.error!)
                                      return
                                  }
                                  if let value: AnyObject = response.result.value{
                                      let post = JSON(value)
                                      print(post)
                                      result = JSON(value)                                    }
                              }
                          case .Failure( _):
                              print("failure")
                              break
                          }
          }
      )
  
      //print("res: \(result)")
      return result
  
  }
  </code></pre>