mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Mutable And Immutable Changing
Added how to switch objects between the two types with examples.
This commit is contained in:
parent
66bc42e31b
commit
b78a67c9fc
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user