On Jul 27, 2013, at 8:29 AM, dangerwillrobinsondan...@gmail.com wrote:

> Ok so I went and looked at sys/time.h and friends and the man page for 
> gettimeofday()
> And now understand how this struct works. 
> It's literally the same as the NSDate method timeIntervalSince1970
> The only difference is NSTimeInterval is representing the values if these 
> struct fields as the respective sides of the decimal point. 
> I grok this. 
> If I want to fire my timer at the second, just supply a tp with tp.tv_usec as 
> zero.

Well, not quite.  gettimeofday() fills in a struct timeval and a struct 
timezone.  dispatch_walltime() takes a struct timespec as its first parameter.  
timeval+timezone vs. timespec.  It's not entirely clear how you would map from 
the first to the second.  I suppose you could check the source for 
dispatch_walltime() to see how it does it.  I recommended continuing to pass 
NULL for the timespec so that dispatch_walltime() would just do it for you and 
instead pass a delta that adjusts this to (approximately) the next whole second.

But, yes, if you know the correct way to fill in the timespec for "now" and you 
bump it up to the next whole second by incrementing its tv_sec field and 
zeroing its tv_nsec, then that would also work.


> Thanks Ken, you set me on the right track.

You're welcome.  Don't forget Rick Mann's original reply, which was along the 
same lines but using NSTimer.  (Which may still be a simpler way to go, since 
you're reliant on the main thread being responsive anyway.)

Cheers,
Ken
_______________________________________________

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