Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.
/ RateLimit Public archive

Simple utility for only executing code every so often.

License

Notifications You must be signed in to change notification settings

soffes/RateLimit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAMRateLimit

Simple utility for only executing code every so often.

This will only execute the block passed for a given name if the last time it was called is greater than limit or it has never been called.

This is really handy for refreshing stuff in viewDidAppear: but preventing it from happening a ton if it was just refreshed.

SAMRateLimit is tested on iOS 6 and requires ARC. It also works on Mac OS X. Fully thread-safe. Released under the MIT license.

Usage

[SAMRateLimit executeBlock:^{
    // Do some work that runs a maximum of once per minute
} name:@"RefreshTimeline" limit:60.0];

SAMRateLimit doesn't persist limts across application launches. For most cases, this is ideal. If you need persistence, simply replace SAMRateLimit with SAMPersistentRateLimit for on disk persistence. Easy as that.

Open up the included Xcode project for an example app and tests. See the header for full documentation.

Installation

Simply add the files in the SAMRateLimit directory to your project or add SAMRateLimit to your Podfile if you're using CocoaPods.