On Jan 12, 2012, at 10:57 PM, Andrew wrote:

> I have a download controller with an NSMutableArray and an
> NSArrayController hooked up to a NSTableView with a view based setup.
> My array contains custom download objects. Each of those has a
> NSURLDownload instance.
> 
> Basically, I am showing a browser-download like interface with size
> downloaded, total expected size, a progress bar, time elapsed,
> download rate and estimated time left.
> 
> It is all working wonderfully, but actually too well. Right now, I am
> using will/didChangeValueForKey messages to notify observers when the
> number of bytes downloaded changes. I am doing this in the callback
> method:
> 
> - (void)download:(NSURLDownload *)download
> didReceiveDataOfLength:(NSUInteger)length
> {
>  [self willChangeValueForKey:@"bytesDownloaded"];
>  _bytesDownloaded += length;
>  [self didChangeValueForKey:@"bytesDownloaded"];
> }
> 
> The result of this is that the UI updates really frequently and the
> estimated time to complete and the download rate jump around a lot. I
> would love it if I could tell cocoa to only update the UI once per
> second instead of immediately when the property key changes.

It may well be your calculation. Do you keep a byte count array and average 
over that? This kind of approach usually smooths out jumps in data size after 
the first few.

Other than that, there isn't really anything you can do except update bytes 
only via a timer, but even that won't work all the time if you consistently 
experience data jumps. Unless you slow the timer down to a point that might be 
user-unfriendly… This approach might require a lot of trial and error to get 
right.

Anyway, all the timer callback has to do is send the willChange/DidChange, 
which doesn't sound very messy to me.

Alternatively, of course, you could use BSD sockets and control the data 
buffering to force consistency.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to