title: Calling completion handler within nested closure to stop recursive function
body: <p>My program pulls from an API to return appointment data into a widget.  I set up a closure to handle pulling an unknown number of pages from the API.  Each time loadResults is called, it queries the API, starting with page 1, and then checks to see if there are any pages left and calls itself again if any pages are remaining to pull.  Once all pages of the API are pulled and loaded into my array, it stops running.</p>
  <p>I'm loading the getAllResults function in my getTimeline function and would like to wait until it's finished running to then load my timeline Entry.</p>
  <p>Is there a way to put an optional completion handler on getAllResults so I can use this function to then load my timeline entry once the completion handler finishes?  Since I'm calling it multiple times I'd like to let it run recursively until finished and be able to alert the timeline it's finished and ready to load.</p>
  <p>Current code:</p>
  <pre><code>func getAllResults(){
      loadResults { (pageReturned) in
          if pageReturned == Int(totalPages)! {
              pages = 1
              parseData(apptReturn: apptList)
              //end the call
          } else if pageReturned &lt; Int(totalPages)! {
              pages = pages + 1
              getAllResults()
                 
              }
  
          }
      }
  </code></pre>
  <p>I was thinking something like this to name the completion handler and call it within the nested closure (but this doesn't work).  Is there a way to reference the getAllResults completion within the loadResults closure?</p>
  <pre><code>func getAllResults(completedResults completion: @escaping (Bool) -&gt; ()){
      loadResults { (pageReturned) in
          if pageReturned == Int(totalPages)! {
              pages = 1
              parseTodayData(apptReturn: apptList)
              getAllResults(completedResults: true) //error: Cannot convert value of type 'Bool' to expected argument type '(Bool) -&gt; ()'
  
              //end the call
          } else if pageReturned &lt; Int(totalPages)! {
  
              pages = pages + 1
              getAllResults(completedResults: false). //error: Cannot convert value of type 'Bool' to expected argument type '(Bool) -&gt; ()'
                  //
              }
                  //
              }
  
          }
  </code></pre>