On Oct 1, 2012, at 8:59 AM, Koen van der Drift <koenvanderdr...@gmail.com> 
wrote:

> Ok, I decided to use NSOperation(Queue) as it is generally recommended
> over performSelectorXXX to be a more modern API, and have been reading
> a bit about it.  In Hillegass' Cocoa book, he uses processQueue
> addOperationWithBlock, in other examples on the webs, people make
> subclasses of NSOperation to put their tasks in. What's the difference
> between these two appraches (if any)?

Playing around with NSOperationQueue, and I implemented it as follows. I use 
this method to do some calculations, and store the results in a table.

- (void)doMyTask 
{
    [self cleanUp];  // clear the NSTableView

    NSOperationQueue    *myQueue = [[NSOperationQueue alloc] init];
        
    [myQueue addOperationWithBlock:^(void)
    {
        [self parseData];       // calculate the new data and update the model
        }];
    
 // now tell everyone we're done
    [self finishedTask];                // update the NSTableView and the UI
}

This works, and is faster than before, but if I run this several times in a 
row, at one point I get a crash, somewhere in the parseData routine.  It could 
happen after ten times, or even after one time. But always at the same point:

                    [self willChangeValueForKey:@"myArray"];
                    [self.myArray addObject: newObject];
                    [self didChangeValueForKey:@"myArray"];

This is called during the parse, when I update the myArray property as a result 
of the parsing.

Any idea what could be going on?

- Koen.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to