Mutable And Immutable Changing

Added how to switch objects between the two types with examples.
This commit is contained in:
Tolga Beser 2015-10-15 14:09:36 -07:00
parent 66bc42e31b
commit b78a67c9fc

View File

@ -148,7 +148,13 @@ int main (int argc, const char * argv[])
[mutableDictionary setObject:@"value1" forKey:@"key1"]; [mutableDictionary setObject:@"value1" forKey:@"key1"];
[mutableDictionary setObject:@"value2" forKey:@"key2"]; [mutableDictionary setObject:@"value2" forKey:@"key2"];
[mutableDictionary removeObjectForKey:@"key1"]; [mutableDictionary removeObjectForKey:@"key1"];
// Change types from Mutable To Immutable
//In general [object mutableCopy] will make the object mutable whereas [object copy] will make the object immutable
NSMutableDictionary *aMutableDictionary = [aDictionary mutableCopy];
NSDictionary *mutableDictionaryChanged = [mutableDictionary copy];
// Set object // Set object
NSSet *set = [NSSet setWithObjects:@"Hello", @"Hello", @"World", nil]; NSSet *set = [NSSet setWithObjects:@"Hello", @"Hello", @"World", nil];
NSLog(@"%@", set); // prints => {(Hello, World)} (may be in different order) NSLog(@"%@", set); // prints => {(Hello, World)} (may be in different order)