title: Swift 3 compatibility version not working with Alamofire
body: <p>I have below code working perfectly fine with Swift 2.2:</p>
  
  <pre><code>import Alamofire
  
  struct Communication {
  
      static let foneKey = "fone"
      static let emailKey = "email"
      static let countryKey = "country"
  
      enum Router: URLRequestConvertible {
          case Init(String, String, String)
  
          var URLRequest: NSMutableURLRequest {
  
              let result: (path: String, method: Alamofire.Method, parameters: [String: AnyObject]) = {
  
                  switch self {
                  case .Init(let fone, let email, let country):
                      let params = [foneKey: fone, emailKey: email, countryKey: country]
                      return ("Init", .POST, params)
                  }
              }()
  
              let URL = NSURL(string: baseURLString)
              let request = NSMutableURLRequest(URL: URL!.URLByAppendingPathComponent(result.path))
              let encoding = ParameterEncoding.JSON
              request.HTTPMethod = result.method.rawValue
              request.URLRequest.HTTPMethod = result.method.rawValue
  
              return encoding.encode(request, parameters: result.parameters).0
          }
      }
  }
  </code></pre>
  
  <p>But when I made above code Swift 3.0 compatible, then it is not working as expected. Below is the Swift 3.0 code where I get a crash at line <code>let request = NSMutableURLRequest(url: URL!.appendingPathComponent(result.path))</code></p>
  
  <pre><code>import Alamofire
  
  struct Communication {
  
      static let foneKey = "fone"
      static let emailKey = "email"
      static let countryKey = "country"
  
      enum Router: URLRequestConvertible {
          /// Returns a URL request or throws if an `Error` was encountered.
          ///
          /// - throws: An `Error` if the underlying `URLRequest` is `nil`.
          ///
          /// - returns: A URL request.
          public func asURLRequest() throws -&gt; URLRequest {
              return URLRequest
          }
  
          case init(String, String, String)
  
          var URLRequest: URLRequest {
  
              let result: (path: String, method: Alamofire.HTTPMethod, parameters: [String: AnyObject]) = {
  
                  switch self {
                  case .init(let foneKey, let email, let country):
                      let params = [foneKey: fone, emailKey: email, countryKey: country]
                      return ("Init", .post, params as [String : AnyObject])
                  }
              }()
  
              let URL = Foundation.URL(string: baseURLString)
              let request = NSMutableURLRequest(url: URL!.appendingPathComponent(result.path))
              let encoding = URLEncoding.methodDependent
              request.httpMethod = result.method.rawValue
  //            request.URLRequest.HTTPMethod = result.method.rawValue
  
              var request1: URLRequest?
              do {
                  request1 = try encoding.encode(self, with: result.parameters)
              } catch {
                  print("error in URLRequest encoding...")
              }
                  return request1!
  //            return encoding.encode(request, parameters: result.parameters).0
          }
      }
  }
  </code></pre>
  
  <p>Below is the image of crash:
  <a href="https://i.stack.imgur.com/35Gxp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/35Gxp.png" alt="enter image description here"></a></p>
  
  <p><strong>Reason of the crash is an Infinite Loop at the above said line.</strong></p>
  
  <p>I guess there is some issue with Request object creation, but not sure what I am missing. I tried few of the alternatives than above code but none of them worked.</p>
  
  <p>For more information, below is the method calling way for me:</p>
  
  <pre><code>func communicate() {
          Alamofire.request(Communication.Router.init("8765432453", "xyz@abc.com", "1").URLRequest as URLRequestConvertible).responseJSON(options: [JSONSerialization.ReadingOptions.allowFragments, JSONSerialization.ReadingOptions.mutableContainers]) { (response) -&gt; Void in
              switch response.result {
              case .success:
                  if let value = response.result.value {
                      // code handled
                  }
              case .failure(let error):
                  print(error)
              }
          }
      }
  </code></pre>
  
  <p>What is the possible solutions to above problem? One solution that is working is creating Request separately works for me. But I want to have above generic solution which is currently implemented in my application with Swift 2.2.</p>