Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is NSFrozenDictionaryM?

I came across NSFrozenDictionary while debugging an app.

NSFrozenDictionary

Shared index property declared as NSDictionary * sharedIndex = ...

What is it? How is it different from NSMutableDictionary?

like image 761
0rt Avatar asked Jan 16 '18 21:01

0rt


1 Answers

It is an NSMutableDictionary marked as immutable.

One case to get __NSFrozenDictionaryM:

  1. Have an array of mutable dictionaries:

    NSArray *array = @[{NSMutableDictionary}, {NSMutableDictionary}, {NSMutableDictionary}]

  2. Making a two-level-deep copy of it by:

    NSArray *res = [[NSArray alloc] initWithArray:array copyItems:YES]

The resulting res array contains immutable copies of NSMutableDictionaries in array, which are of type __NSFrozenDictionaryM. I guess this is an optimisation to avoid really copying all dictionaries in the original array.

like image 158
Zhigang An Avatar answered Nov 15 '22 22:11

Zhigang An