title: Assign Value from Closure to Variable Swift
body: <p>I'm trying to assign the value I get back from a closure to a variable I have assigned outside the scope of the closure.</p>
  
  <p>I want to do this so i'm able to use this var outside my closure in order to be neat and not have all this nested code inside this closure.</p>
  
  <p>I am using Alamofire for the requests and swify-json to help parse the json.</p>
  
  <p>I'm getting the following: </p>
  
  <pre><code>Error: variable 'userId' captured by a closure before being initialized
  </code></pre>
  
  <p>Here is my code calling my closure function:</p>
  
  <pre><code>var userId: Int
  
  get()
  {
      data in
      userId = data["used_id"].intValue
  }
  </code></pre>
  
  <p>Here is my implementation of my get() function:</p>
  
  <pre><code>func get(param: [String: AnyObject] = [String: AnyObject](), completion: (JSON) -&gt; ())
  {
      Alamofire.request(.GET, "apiendpoint.com", parameters: param)
      .responseJSON
      {
          response in
              switch response.result
              {
                  case .Success:
                      let jsonData = JSON(data: response.data!)
                      completion(jsonData)
                  case .Failure(let error):
                      print("Request failed with error: \(error)")
              }
      }
  }
  </code></pre>
  
  <p>Thank you for any and all help!</p>