Amazon.com Widgets Exercise 3
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2014, 07:43:17 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Programming in Objective-C, 4th edition
| |-+ Exercises
| | |-+ Chapter 18
| | | |-+ Exercise 3
Pages: [1] Go Down
Print
Author Topic: Exercise 3 (Read 1065 times)
Brabbeldas
Newbie
*
Posts: 10






on: January 26, 2012, 07:35:28 AM

Code: (Objective-C)
#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
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.