Created
February 18, 2012 04:17
-
-
Save meiwin/1857364 to your computer and use it in GitHub Desktop.
Caching with GCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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