Home Ask Login Register

Developers Planet

Your answer is one click away!

Ben February 2016

What is the difference between [NSMutableDictionary dictionary] and [NSMutableDictionary new]?

When creating a new NSDictionary object in Objective-C, you can do either:

NSMutableDictionary *dict= [NSMutableDictionary dictionary];
// or 
NSMutableDictionary *dict= [NSMutableDictionary new];

I was wondering what is the difference between those two?


Jacob Gorban February 2016

There's probably no functional difference. new is a short form for [[Class alloc] init] form and works with all classes. dictionary is specific method for NSDictionary but is used for NSMutableDictionary to create an empty dictionary.

In the past, before ARC, dictionary would return an autoreleased object and new would return a retained one. That's probably the main difference between these two.

Post Status

Asked in February 2016
Viewed 2,024 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life