Created
November 17, 2016 08:07
-
-
Save Adlai-Holler/76f74a7e659996dcb688ecc901770ddb to your computer and use it in GitHub Desktop.
A test to ensure that NSCache doesn't give up after multiple memory warnings.
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
- (void)testThatNSCacheDoesntGiveUp | |
{ | |
NSCache *cache = [[NSCache alloc] init]; | |
for (NSInteger i = 0; i < 5; i++) { | |
// Add a couple entries for good measure | |
[cache setObject:(id)kCFNull forKey:[NSUUID UUID]]; | |
[cache setObject:(id)kCFNull forKey:[NSUUID UUID]]; | |
[self expectationForNotification:UIApplicationDidReceiveMemoryWarningNotification object:nil handler:nil]; | |
NSLog(@"Awaiting memory warning…"); | |
[self waitForExpectationsWithTimeout:30 handler:nil]; | |
} | |
// Now that we've sent two memory warnings, ensure the cache still works. | |
NSUUID *newKey = [NSUUID UUID]; | |
[cache setObject:(id)kCFNull forKey:newKey]; | |
XCTAssertNotNil([cache objectForKey:newKey]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment