Created
March 10, 2017 21:15
-
-
Save Catfish-Man/954a4b7a65bb5c7e03af57cac36d16d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| static id cachedObject; | |
| static NSLock *lock; | |
| id getCachedObject() { | |
| [lock lock]; | |
| id result = [cachedObject retain]; | |
| [lock unlock]; | |
| return result; | |
| } | |
| void setCachedObject(id newObject) { | |
| [lock lock]; | |
| [cachedObject release]; | |
| cachedObject = [newObject retain]; | |
| [lock unlock]; | |
| } | |
| //then in client code… | |
| id object = getCachedObject(); | |
| [object doSomething]; | |
| [object release]; //not locked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment