title: ImageIO Error When Creating ICNS File
body: <p>This code (<code>source</code> is an <code>NSMutableArray</code> with <code>NSImage</code> objects:</p>
  
  <blockquote>
  <pre><code>NSURL *fileURL = [NSURL fileURLWithPath:aPath];
  CGImageDestinationRef dr = CGImageDestinationCreateWithURL((CFURLRef)fileURL,
                                                             kUTTypeAppleICNS,
                                                             1,
                                                             NULL);
  
  for (NSImage *img in source) {
  
      NSLog(@"%@",img);
      CGImageRef i1 = [img CGImageForProposedRect:NULL context:nil hints:nil];
      CGImageDestinationAddImage(dr, i1, NULL);
  
  }
  
  CGImageDestinationFinalize(dr);
  CFRelease(dr);
  </code></pre>
  </blockquote>
  
  <p>Resulted in the following output :</p>
  
  <blockquote>
    <p>2012-12-26 13:48:57.682 Eicon[1131:1b0f] |NSImage 0x1025233b0 Size={11.52, 11.52} Reps=(
        "NSBitmapImageRep 0x10421fc30 Size={11.52, 11.52} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=1024x1024 Alpha=NO Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x104221170"</p>
    
    <p>(...) &lt;- here the other NSImage instances are logged.</p>
    
    <p><strong>ImageIO: |ERROR|  CGImageDestinationFinalize image destination does not have enough images</strong></p>
  </blockquote>
  
  <p>Any ideas why it ends with the error at the end? (BTW, I thought of using IconFamily instead but a lot of the methods it uses are deprecated).</p>
  
  <p>EDIT : Maybe it'd be more important to mention the code I use to generate the images, I wouldn't be surprised if that code has problems (I'm a noob) : </p>
  
  <pre><code>// Get images
  [source removeAllObjects];
  NSSize sizes[10];
  sizes[0] = NSMakeSize(1024,1024);
  sizes[1] = NSMakeSize(512,512);
  sizes[2] = NSMakeSize(512,512);
  sizes[3] = NSMakeSize(256,256);
  sizes[4] = NSMakeSize(256,256);
  sizes[5] = NSMakeSize(128,128);
  sizes[6] = NSMakeSize(64,64);
  sizes[7] = NSMakeSize(32,32);
  sizes[8] = NSMakeSize(32,32);
  sizes[9] = NSMakeSize(16,16);
  for (int i=0 ; i&lt;10 ; i++) {
      if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"Size%i",i+1]]) {
          NSBitmapImageRep *srcimg = [[NSBitmapImageRep alloc] initWithData:[NSData dataWithContentsOfFile:aFile]];
          [srcimg setPixelsHigh:sizes[i].height];
          [srcimg setPixelsWide:sizes[i].width];
          NSImage *newimg = [[NSImage alloc] initWithSize:NSZeroSize];
          [newimg addRepresentation:srcimg];
          if (![newimg isValid]) {
              [delegate error:@"Invalid file."];
          }
          else [source addObject:newimg];
      }
  }
  </code></pre>