title: Swift: Pass data to a closure that captures context
body: <p>I am trying to call a function when the internet connection is restored and the <code>updateOnConnection</code> variable is true. Here is my code:</p>
  
  <pre><code>func checkForConnection() {
      let host = "reddit.com"
      var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil)
      let reachability = SCNetworkReachabilityCreateWithName(nil, host)!
  
      SCNetworkReachabilitySetCallback(reachability, { (_, flags, _) in
          if flags.rawValue == 0 { //internet is not connected
  
          } else { //internet became connected
              if self.updateOnConnection {
                  self.refreshWallpaper()
              }
          }
      }, &amp;context)
  
      SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes)
  }
  </code></pre>
  
  <p>My problem is that the lines: </p>
  
  <pre><code>        if self.updateOnConnection {
              self.refreshWallpaper()
          }
  </code></pre>
  
  <p>cause the error: "<code>A C function pointer cannot be formed from a closure that captures context</code>"</p>
  
  <p>I am not sure how to check the state of <code>updateOnConnection</code> and call <code>refreshWallpaper()</code> in the closure that monitors changes in the internet connection. How can I fix this, or is there a totally different workaround I should be using?</p>