From b78a67c9fc29aac44848707f8119048286890a8d Mon Sep 17 00:00:00 2001 From: Tolga Beser Date: Thu, 15 Oct 2015 14:09:36 -0700 Subject: Mutable And Immutable Changing Added how to switch objects between the two types with examples. --- objective-c.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'objective-c.html.markdown') diff --git a/objective-c.html.markdown b/objective-c.html.markdown index cf6bf780..30bb8843 100644 --- a/objective-c.html.markdown +++ b/objective-c.html.markdown @@ -148,7 +148,13 @@ int main (int argc, const char * argv[]) [mutableDictionary setObject:@"value1" forKey:@"key1"]; [mutableDictionary setObject:@"value2" forKey:@"key2"]; [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 NSSet *set = [NSSet setWithObjects:@"Hello", @"Hello", @"World", nil]; NSLog(@"%@", set); // prints => {(Hello, World)} (may be in different order) -- cgit v1.2.3 From 3a968a826b621c0e484268532d6b96a7b2865c8a Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Sun, 18 Oct 2015 12:22:33 -0500 Subject: Fix issue with calling block code. Fixes https://github.com/adambard/learnxinyminutes-docs/issues/1598 --- objective-c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'objective-c.html.markdown') diff --git a/objective-c.html.markdown b/objective-c.html.markdown index 30bb8843..f130ea0c 100644 --- a/objective-c.html.markdown +++ b/objective-c.html.markdown @@ -688,7 +688,7 @@ addUp = ^(int n) { // Remove (int n) to have a block that doesn't take in any pa mutableVar = 32; // Assigning new value to __block variable. return n + outsideVar; // Return statements are optional. } -int addUp = add(10 + 16); // Calls block code with arguments. +int addUp = addUp(10 + 16); // Calls block code with arguments. // Blocks are often used as arguments to functions to be called later, or for callbacks. @implementation BlockExample : NSObject -- cgit v1.2.3