title: objective c help with custom delegates and asynchronous data
body: <p>I am posting entries from a persistent core data store asynchronously to a web server. I would like to delete each associated managed object after a successful post. </p>
  
  <p>My problem is that I am concurrently populating the store and making posts so I can't do a serial post / delete operation. Is there a way to mark an object for deletion until it's  associated <code>connectionDidFinishLoading</code> call has been made, then delete it? </p>
  
  <p>I am also assuming that by using asynchronous <code> NSURLRequests</code>, the application spawns multiple <code>NSURLConnections</code> and runs them concurrently. Am I wrong in this assumption?</p>
  
  <hr>
  
  <p>(Update) Thanks to Uberhamster's advice I tried to use delegates but I am failing. This is how I am going about this problem.I have declared a protocol in the class that handles the posts because that is where <code>connectionDidFinishLoading</code> lives.</p>
  
  <pre><code>@protocol postDelegate 
  @optional
  - (void)postCompleted;
  @end
  
  @interface makePosts : NSObject {
       //...
       id &lt;postsDelegate&gt; delegate;
  }
  
  @property (nonatomic, assign) id &lt;postsDelegate&gt; delegate;
  //...
  @end
  
  @implementation makePosts
      @synthesize delegate;
      //...
      - (void) connectionDidFinishLoading {
          [delegate postCompleted];
      }
      //...
  @end
  </code></pre>
  
  <p>And in the class that grabs data from the persistent store and spawns <code>NSURLConnections</code> this is what I'm doing:</p>
  
  <pre><code>@interface myClass &lt;postsDelegate&gt;
      //...
      makePosts* makePostsObject;
  @end
  
  @implementation myClass
  - (void) batchPost {
        //...
        for(NSManagedObject* obj in items) {
            makePostsObject = [[makePosts alloc] init]; 
            makePostsObject.delegate = self;
            [makePostsObject setEntryName:[obj valueForKey:@"name"]]; // set reference here
            NSString* post_data = [NSString stringWithString:[self createXMLPost:obj]];
            [makePostsObject postdata:[obj valueForKey:@"name"]];
            [makePostsObject release];
      }
  
  
        - (void) postCompleted
          {
               NSLog(@"posted entry for: %@", makePostsObject.entryName);
          }
  
  @end
  </code></pre>
  
  <p>I think what I am doing wrong is making <code> myClass </code> the delegate? <code>postCompleted</code> is called for every post that I make, but the reference each time is for the last post. Is there a way to get back the delegate from the callback function?</p>