An Objective-C timer that restricts firing to a time range. If it's called BEFORE min, it waits for min. If it's called AFTER max, it's called at max.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
MTTimer.xcodeproj
MTTimer
MTTimerTests
.gitignore Initial commit Sep 7, 2013
LICENSE Initial commit Sep 7, 2013
MTTimer.podspec fixing typo in podspec Sep 7, 2013
README.md updating readme Sep 7, 2013

README.md

MTTimer

An Objective-C timer that restricts firing to a time range. If it's dismissed BEFORE min, it waits for min. If it's dismissed AFTER max, it's called at max.

Developed for Firehose by Mysterious Trousers

Installation

Using CocoaPods, add this line to your Podfile:

pod "MTTimer"

Example

@implementation FMRootWindowView {
	MTTimer *_durationTimer;
}

#pragma mark - Public

- (void)displayLoadingWithMessage:(NSString *)message
{
	...

	// It's kind of jolting to see a loading message pop up and disappear in 
	// just a few miliseconds, in the case of a request that loads very quickly, 
	// so we constrain the timer to not fire until at least 2 seconds, even if
	// `done` is called before that.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:2 untilPerformingBlock:^{
        // do whatever you do when it's done
    }];

    ...
}

- (void)displaySuccessWithMessage:(NSString *)errorMessage
{
	...

	// We want a the success message to show for at least 2 seconds, but we 
	// don't want it showing more than 4.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:2 atMost:4 beforePerformingBlock:^{
        // do whatever you do when it's done
    }];

    ...
}

- (void)displayErrorWithMessage:(NSString *)errorMessage
{
	...
	
	// We want a the error message to show for at least 30 seconds, to make 
	// sure the user sees it.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:30 atMost:35 beforePerformingBlock:^{
        [self animateUp];
    }];

	...
}

- (void)dismissStatus
{
	// This is called whenever your external operation is complete. If `done` is calle BEFORE
	// the min seconds has been reached, the completion block will not fire until min is reached.
	// If you call this AFTER max, the completion block will have already fired when max was reached.
    [_durationTimer done];
}

@end

Contributing

Please update and run the tests before submitting a pull request. Thanks.

Author

Adam Kirk (@atomkirk)