Codec ░ time

420Getting current Time with Microseconds

#import <sys/time.h>
 
struct</span> timeval tv;
gettimeofday(&tv, NULL);
int sec = tv.tv_sec;
int usec = tv.tv_usec;

The system’s notion of the current Greenwich time and the current time zone is obtained with the gettimeofday() call, and set with the ettimeofday() call. The time is expressed in seconds and microseconds since midnight (0 hour), January 1, 1970. The resolution of the system clock is hardware dependent, and the time may be updated continuously or in “ticks.” If tp is NULL and tzp is non-NULL, gettimeofday() will opulate the timezone struct in tzp. If tp is non-NULL and tzp is NULL, then only the timeval struct in tp is populated. If both tp and tzp are NULL, nothing is returned.

Check out the man page for more info.

632Inline Functions in C 569Layering one UIImage onto of another UIImage 560#import vs #include in Objective C – A quick reminder 457Singleton Classes and Shared Resources in Objective-C 452Padding with Zeros (or other characters)

87Absolute Time

Several ways:

CFAbsoluteTime abso = CFAbsoluteTimeGetCurrent();
NSTimeInterval inter = [NSDate timeIntervalSinceReferenceDate];

Plus other, more unix intrinsic methods like gettimeofday and mach_absolute_time. The above mentioned methods shall suffice for our needs.

420Getting current Time with Microseconds 58Delay method execution & passing objects along the way 35Delay method execution

58Delay method execution & passing objects along the way

Specific example. Deselect table cell after a certain time. TableView and indexPath are wrapped into an array and send along to the method for delayed execution.


- (void)tableView:(UITableView *)tView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"User selected row %d\n", [indexPath row] + 1);
// actions
[self performSelector:@selector(deselectTableCell:) withObject:[NSArray arrayWithObjects:tView, indexPath, nil] afterDelay:0.2f];
}

-(void) deselectTableCell:(NSArray *)array {
[[ [array objectAtIndex:0] cellForRowAtIndexPath:[array objectAtIndex:1] ] setSelected:NO];
NSLog(@"deselectTableCell" );
}

In additon to http://www.trembl.org/codec/35/

594Delaying Methods. And cancelling the delaying of methods 536Adding a custom delegate 420Getting current Time with Microseconds 374Delay method execution, part II 87Absolute Time

35Delay method execution

[self performSelector:@selector(methodName) withObject:nil afterDelay:0.10f];

update: http://www.trembl.org/codec/58/

594Delaying Methods. And cancelling the delaying of methods 536Adding a custom delegate 420Getting current Time with Microseconds 374Delay method execution, part II 87Absolute Time