Created
March 23, 2015 01:17
-
-
Save inamiy/577ae4b222dd38429aa2 to your computer and use it in GitHub Desktop.
mutableArrayValueForKey + weak is not really weak...
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)testExample { | |
MyObject* obj = [[MyObject alloc] init]; | |
obj.array = @[]; | |
NSMutableArray* array = [obj mutableArrayValueForKey:@"array"]; | |
// NSMutableArray* array = @[].mutableCopy; // using this will pass test | |
__weak NSMutableArray* weakArray = array; | |
[array addObject:@1]; | |
XCTAssertTrue([array isEqualToArray:@[@1]]); | |
XCTAssertTrue([weakArray isEqualToArray:@[@1]]); | |
array = nil; | |
XCTAssertNil(array); | |
XCTAssertNil(weakArray); // fail: weakArray is not nil... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment