Skip to content

Instantly share code, notes, and snippets.

@meiwin
Created February 18, 2012 04:17
Show Gist options
  • Save meiwin/1857364 to your computer and use it in GitHub Desktop.
Save meiwin/1857364 to your computer and use it in GitHub Desktop.
Caching with GCD
// as seen in http://www.cocoanetics.com/2012/02/caching-caches/
// benefits: thread-safe
- (id) cachedObject
{
static dispatch_once_t onceToken;
static id objectToCache;
dispatch_once(&onceToken,^{
objectToCache = ...; // create the object
});
return objectToCache
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment