iOS library for testing if a time interval is elapsed.
Execute a block if some 3 seconds elapsed since last time we run the hourglass (or called hourglass_set, see below):
NSString *key = @"my_action";
hourglass_run(key, 3, ^{
// do something if more than 3 seconds since last time we did _my_action_
}, ^{
// do something if less than 3 seconds since last time we did _my_action_
});
Reset the hourglass:
hourglass_clear(key);
Set manually the hourglass:
hourglass_set(key);
Check manually if 5 seconds are elapsed:
BOOL isElapsed = hourglass_elapsed(key, 5);
There are two different hourglasses:
- Hourglass is a collection of dispatch-like functions
- ACHourglass is class where you can set a time interval for a named condition and later check if enough time has passed for that condition.
The two are a little bit different and their usage. See documentation and headers for more.
Note: Unfortunately, appledoc does not support functions; so, the dispatch-like hourglass is not documented by the following procedure.
install appledoc:
brew install appledoc
build the HourglassDocumentation target,
the documentation will be automatically added to Xcode.