Reputation: 900
i have a Question: when we access an "objectForKey"and the key doesn't exist, this ll return nil but no error/exception, so the question is that after this statement/line is executed, does the runtime system creates a key with the name specified and set it nil OR although nil is the output but no such key is created????
Upvotes: 0
Views: 137
Reputation: 4187
You can Log
your dictionary after the line executed to see it.
You will see that NSDictionary
is immutable, it won't modify your dictionary. ;)
Upvotes: 0
Reputation: 6292
No it wont modify the dictionary. If the key does not exist then it simply returns nil value.
To confirm this you can set a breakpoint in Xcode for an invalid key and check if dictionary is modified or not. (And moreover NSDictionary is immutable i.e you cannot add/remove objects)
Upvotes: 1
Reputation: 122458
In a word: No.
NSDictionary
is immutable and objectForKey
is a method on the NSDictionary
class.
Upvotes: 1