Skip to content

Instantly share code, notes, and snippets.

@inamiy
Created March 23, 2015 01:17
Show Gist options
  • Save inamiy/577ae4b222dd38429aa2 to your computer and use it in GitHub Desktop.
Save inamiy/577ae4b222dd38429aa2 to your computer and use it in GitHub Desktop.
mutableArrayValueForKey + weak is not really weak...
- (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