title: Method parameters in nested closure
body: <p>I am trying to understand how parameters passed to a method are available to nested closures. I'm nervous that something I wrote won't always have the original parameters available.</p>
  
  <p>(these are drastically simplified examples)</p>
  
  <p>I have a method that I wrote that specifies a closure as a parameter:</p>
  
  <pre><code>func saveNameAndAgeToServer(serverParams: [String:String], completionHandler: (age: NSNumber) -&gt; ()) {
  
      // Connect to a server
      // POST a name and dob from serverParams
      // Receives a current age in completion:
  
      completionHandler(age: 22)
  }
  </code></pre>
  
  <p>Now somewhere else I create another method, that also specifies a closure, takes two parameters and calls the first function:</p>
  
  <pre><code>func AwesomeFunc(name: String, dob: NSDate, completionHandler: (isOverTwentyOne: Bool) -&gt; ()) {
  
      let formattedDob = NSDateFormatter().stringFromDate(dob)
  
      saveNameAndAgeToServer([name:formattedDob]) { (age) -&gt; () in
  
          if (age as Int) &gt;= 21 {
  
              print("\(name) can have a beer.")
              completionHandler(isOverTwentyOne: true)
  
          } else {
  
              print("\(name) is too young to drink, he can have a water.")
              completionHandler(isOverTwentyOne: false)
          }
      }
  
  }
  </code></pre>
  
  <p>Am I able to guarantee that the parameters (name and dob) passed into this latter function will always be available?</p>
  
  <p>What I'm trying to ask is will the memory that the saveNameAndAgeToServer closure runs within always have the parameters of AwesomeFunc available to it? I'm pretty sure the function is all being held while whatever it calls is completed but would love a 2nd opinion. </p>