Re: NSTextField not updated during large process
Re: NSTextField not updated during large process
- Subject: Re: NSTextField not updated during large process
- From: Mike Abdullah <email@hidden>
- Date: Mon, 01 Oct 2012 23:31:58 +0100
On 1 Oct 2012, at 22:39, Koen van der Drift <email@hidden> wrote:
>
> On Oct 1, 2012, at 8:59 AM, Koen van der Drift <email@hidden> 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?
Yes, you don't understand the consequences of your code yet. AppKit is not threadsafe. You absolutely MUST only update UI on the main thread for something like this.
Make sure your -parseData routine is threadsafe, and then bounce back over to the main thread for -finishedTask.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden