title: Apply a block to all objects of an NSArray
body: <p>Is there a way to apply a block to all the objects of an array?</p>
  
  <p>Let's say I have an amazing block:</p>
  
  <pre><code>void (^myAmazingBlock)(NSNumber *) = ^(NSNumber *aFooNumber) {
      NSLog(@"Log message from an Amazing Block: %@", aFooNumber);
  };
  </code></pre>
  
  <p>To apply my block to all the objects of my array, this works:</p>
  
  <pre><code>for (NSNumber *aNumber in myArray) {
      myAmazingBlock(aNumber);
  }
  </code></pre>
  
  <p>Is it possible to get rid of the fast enumeration loop, and have something similar in the spirit to:</p>
  
  <pre><code>[myArray valueForKeyPath:@"@distinctUnionOfObjects.^myAmazingBlock"]; // This code doesn't work. It's just to show the style of what I'm trying to write.
  </code></pre>
  
  <p>I don't have any specific use in mind ; I was just being curious of the other possible ways to write this.</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>It's possible to use <code>enumerateObjectsUsingBlock:</code> (Thank you paulbailey).<br>
  You then have to declare your block like this:  </p>
  
  <pre><code>void (^myAmazingBlock2)(id, NSUInteger, BOOL *) = ^(id aFooNumber, NSUInteger idx, BOOL *stop) {
      NSLog(@"Amazing BLOCK 2 %@", aFooNumber);
  };
  
  [myArray enumerateObjectsUsingBlock:myAmazingBlock2];
  </code></pre>
  
  <p>Unfortunately, the fast enumeration loop is still the most readable solution.</p>