title: Iphone: Passing objects and Multiple threads
body: <p>Im having some trouble passing an NSNumber object to different threads.
  I call a function on viewDidload that loads up some objects from core data as a background process. which calls another function which loops through the loaded objects to see if there are any images associated with it alredy downloaded. if its not present, download the images asynchronously and save it locally. The thing is I need to perform startDownloadFor:atIndex: on the main thread. But the application crashes because of the NSNumber object thats being passed. here is the code..</p>
  
  <pre><code>- (void)viewDidLoad {
     ...
     ...
     [self performSelectorInBackground:@selector(loadImages) withObject:nil]; 
  }
  
  -(void)loadImages{
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   ...
          ...
   [self fillInImages];
   [pool release];
  }
  
  -(void)fillInImages{
  
   NSString *imageURL;
   for (int i=0; i &lt; [dataManager.objectList count]; i++) {
    ...
    if ([dataManager.RelatedImages Image] == nil) {
     //[self startDownloadFor:imageURL atIndex:[NSNumber numberWithInt:i]; // &lt;&lt; WORKS FINE
     [self performSelectorOnMainThread:@selector(startDownloadFor:atIndex:) withObject:(imageURL, [NSNumber numberWithInt:i]) waitUntilDone:YES]; // &lt;&lt; CRASHES 
     ...
    }else {
     ...
    }
    ...
   }
   ...
  }
  
  -(void)startDownloadFor:(NSString*)imageUrl atIndex:(int)indexPath{
  
   NSString *indexKey = [NSString stringWithFormat:@"key%d",indexPath];
   ...
  }
  </code></pre>
  
  <p>what is the right way of doing this?</p>
  
  <p>Thanks</p>