title: How do a put a block (closure) in a variable in Objective-C?
body: <p>Being used to Swift I have worked a bit with closures both as <code>parameters</code> and as <code>variables</code>. I'm trying to translate that into Objective-C now. I have managed to create a simple <code>block</code> like this:</p>
  
  <pre><code>-(void)myFunc:(void(^)(void))callback {
      callback();
  }
  </code></pre>
  
  <p>And from <code>viewDidLoad()</code></p>
  
  <pre><code>[self myFunc:^{
          NSLog(@"MyCallBack");
      }];
  </code></pre>
  
  <p>Now I would like to put the <code>block</code> in a <code>variable</code>. In Swift it would be something like this: </p>
  
  <p>Defining <code>variable</code></p>
  
  <pre><code>var completionHandler: (() -&gt; ())?
  </code></pre>
  
  <p>using it as completion in a <code>function</code> or whatever:</p>
  
  <pre><code>DispatchQueue.main.async {
      self.completionHandler?()
  }
  </code></pre>
  
  <p>and the actually <code>callback</code></p>
  
  <pre><code>completionHandler = { 
       //DOSTUFF
  }
  </code></pre>
  
  <p>How would this translate to Objective-C?</p>
  
  <p>Something like... declaring </p>
  
  <pre><code>void (^completion)(void); 
  </code></pre>
  
  <p>using (this doesn't seem right. I get a warning that it's unused)</p>
  
  <pre><code>completion;
  </code></pre>
  
  <p>and <code>callback</code></p>
  
  <pre><code>completion = ^void(void){
      NSLog(@"YAY");
  };
  </code></pre>
  
  <p>So what's missing?</p>