0

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?

Brian
  • 14,610
  • 7
  • 35
  • 43
Ben
  • 946
  • 1
  • 11
  • 19

1 Answers1

2

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.

Jacob Gorban
  • 1,431
  • 1
  • 9
  • 15