title: Objective-C blocks and variables
body: <p>I've started using Objective-C blocks today. I wrote the following code:</p>
  
  <pre><code>NSArray *array = @[@25, @"abc", @7.2];
  
  void (^print)(NSUInteger index) = ^(NSUInteger index)
  {
      NSLog(@"%@", array[index]);
  };
  
  for (int n = 0; n &lt; 3; n++)
      print(n);
  </code></pre>
  
  <p>Which works properly. I needed to change the <code>array</code> variable after its declaration, though, so I tried using the following code:</p>
  
  <pre><code>NSArray *array;
  
  void (^print)(NSUInteger index) = ^(NSUInteger index)
  {
      NSLog(@"%@", array[index]);
  };
  
  array = @[@25, @"abc", @7.2];
  
  for (int n = 0; n &lt; 3; n++)
      print(n);
  </code></pre>
  
  <p>However, that doesn't work. The console just prints <code>(null)</code> three times. Why is it that this doesn't work, while it did work with my first piece of code?</p>