Error: “Pattern cannot match values of type 'URLRequest'” in swift

后端 未结 2 943
盖世英雄少女心
盖世英雄少女心 2021-01-28 00:57

My code was working perfectly in before.. recently i have installed Alamofire in other project now below error throwing.

Pattern cannot ma

2条回答
  •  庸人自扰
    2021-01-28 01:21

    Error is related to a small mistake(i.e .success syntax according to Alomofire, and change AF as Alamofire), I have correct the Syntax as well as code. Now you can use as follows:-

    func postImageRequestWithURL(withUrl strURL: String,withParam postParam: Dictionary,withImages imageArray:NSMutableArray,completion:@escaping (_ isSuccess: Bool, _ response:NSDictionary) -> Void) {
    
              Alamofire.upload(multipartFormData: { (MultipartFormData) in
              // Here is your Image Array
              for (imageDic) in imageArray {
                  let imageDic = imageDic as! NSDictionary
                  for (key,valus) in imageDic {
                      MultipartFormData.append(valus as! Data, withName:key as! String,fileName: "file.jpg", mimeType: "image/jpg")
                  }
              }
    
              for (key, value) in postParam {
                  MultipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
              }
              }, usingThreshold: UInt64.init(), to: strURL, method: .post, headers:["userId":"mfjeriefei","key":"cnhsdnchsj"]) {(result) in
              switch result {
              case .success(let upload, _, _): //........here getting error
                  upload.uploadProgress(closure: {(progress) in
                      print("Upload Progress: \(progress.fractionCompleted)")
                  })
                  upload.responseJSON { response in
                      if response.response?.statusCode == 200 {
                          let json = response.result.value as? NSDictionary
                          completion(true,json!);
                      }
                      else {
                          let json = response.result.value as? NSDictionary
                          completion(false,json!);
                      }
                  }
              case .failure(let encodingError)://............here getting error
                  print(encodingError)
                  completion(false,[:]);
              }
          }
      }
    

提交回复
热议问题