A subtle difference is that the dictionaryWithDictionary:
class method returns an autoreleased object, while the mutableCopy
method returns a retained object. If you are using automatic reference counting, there is no difference; if you turn ARC off, you need to send a release
message to the dict
obtained through the second snippet.
1:
If dict2
is nil
, [NSMutableDictionary dictionaryWithDictionary:dict2]
will return an empty dictionary and [dict2 mutableCopy]
will return nil
.
2:
|
|
参考:http://stackoverflow.com/questions/21924656/is-there-a-difference-between-nsmutabledictionary-dictionarywithdictionary-an