title: Store a closure as a variable in Swift
body: <p>In Objective-C, you can define a block's input and output, store one of those blocks that's passed in to a method, then use that block later:</p>
  
  <pre><code>// in .h
  
      typedef void (^APLCalibrationProgressHandler)(float percentComplete);
      typedef void (^APLCalibrationCompletionHandler)(NSInteger measuredPower, NSError *error);
  
      // in .m
  
      @property (strong) APLCalibrationProgressHandler progressHandler;
      @property (strong) APLCalibrationCompletionHandler completionHandler;
  
      - (id)initWithRegion:(CLBeaconRegion *)region completionHandler:(APLCalibrationCompletionHandler)handler
      {
          self = [super init];
          if(self)
          {
              ...
              _completionHandler = [handler copy];
              ..
          }
  
          return self;
  }
  
  - (void)performCalibrationWithProgressHandler:(APLCalibrationProgressHandler)handler
  {
      ...
  
              self.progressHandler = [handler copy];
  
       ...
              dispatch_async(dispatch_get_main_queue(), ^{
                  _completionHandler(0, error);
              });
       ...
  }
  </code></pre>
  
  <p>So I'm trying to do the equivilant in Swift:</p>
  
  <pre><code>var completionHandler:(Float)-&gt;Void={}
  
  
  init() {
      locationManager = CLLocationManager()
      region = CLBeaconRegion()
      timer = NSTimer()
  }
  
  convenience init(region: CLBeaconRegion, handler:((Float)-&gt;Void)) {
      self.init()
      locationManager.delegate = self
      self.region = region
      completionHandler = handler
      rangedBeacons = NSMutableArray()
  }
  </code></pre>
  
  <p>The compiler doesn't like that declaration of completionHandler. Not that I blame it, but, how do I define a closure that can be set and used later in Swift?</p>