Skip to content

Instantly share code, notes, and snippets.

@bgerstle
Last active August 29, 2015 14:15
Show Gist options
  • Save bgerstle/4b23a5c4b6b7323b7b1a to your computer and use it in GitHub Desktop.
Save bgerstle/4b23a5c4b6b7323b7b1a to your computer and use it in GitHub Desktop.
Some tests demonstrating copying behavior of immutable and mutable dictionaries.
- (void)testCopyReturnsImmutable
{
NSDictionary* immutable = @{@"foo": @"bar"};
NSMutableDictionary* mutable = [immutable mutableCopy];
NSDictionary* copyOfMutable = [mutable copy];
XCTAssertFalse([copyOfMutable isMemberOfClass:[NSMutableDictionary class]]);
// interestingly, the class is actually __NSDictionaryI, so you can't assert isMemberOfClass:NSDictionary
XCTAssertTrue([copyOfMutable isKindOfClass:[NSDictionary class]]);
}
- (void)testCopyOfImmutableReturnsSelf
{
NSDictionary* test = @{@"foo": @1};
XCTAssertEqual(test, [test copy], @"Expected copies of immutable objects to be the objects themselves.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment