title: Swift: Escaping closure captures non-escaping parameter 'onCompletion'
body: <p>I have a problem with my swift. I am trying to send an API request and then retrieve data but I get the following error message:</p>
  <blockquote>
  <p>&quot;Swift: Escaping closure captures non-escaping parameter 'onCompletion'&quot;.</p>
  </blockquote>
  <p>Does anyone know how I can solve this? thanks in advance</p>
  <p>Code:</p>
  <pre><code>
  class RestApiManager: NSObject {
      static let sharedInstance = RestApiManager()
      
      let baseURL = &quot;http://api.randomuser.me/&quot;
      
      func getRandomUser(onCompletion : (JSON) -&gt; Void) {
          makeHTTPGetRequest(path: baseURL, onCompletion: { json, err -&gt; Void in
              onCompletion(json)
          })
      }
      
      func makeHTTPGetRequest(path: String, onCompletion: ServiceResponse) {
          let request = NSMutableURLRequest(url : URL(string: path)! as URL)
          
          let session = URLSession.shared
          
          let task = session.dataTask(with: request as URLRequest, completionHandler: { data, response, error in
              let json:JSON = JSON(data as Any)
              onCompletion(json, error as NSError?)
          })
          task.resume()
      
      }
  }
  </code></pre>