#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
// Create initial dictionary //
NSMutableDictionary *states = [NSMutableDictionary dictionary];
[states setObject:[NSMutableString stringWithString:@"CapitalA"] forKey:@"StateA"];
[states setObject:[NSMutableString stringWithString:@"CapitalB"] forKey:@"StateB"];
[states setObject:[NSMutableString stringWithString:@"CapitalC"] forKey:@"StateC"];
// Create both immutable and mutable copy //
NSDictionary *statesImCopy = [states copy];
NSMutableDictionary *statesMCopy = [states mutableCopy];
// Retrieve the first object from initial dictionary //
NSMutableString *object1 = [states objectForKey:@"StateA"];
// Adjust this particular object //
[object1 setString:@"CapitalAAA"];
// Display initial dictionary //
NSLog(@"Initial: %@", states);
// Display both copies //
NSLog(@"Immutable copy: %@", statesImCopy);
NSLog(@"Mutable copy: %@", statesMCopy);
}
return 0;
}
The above shows that the first object in both copies are also changed, therefore: shallow copy