We have answer of your question!

100% solved queries, no empty question

Question: Why there is No constant NSArray Literal and NSDictionary Literal


0

As apple Introduced a new syntax for array literal and dictionary literals:

NSArray* literalArray = @[@"1", @"2", @"3"];

//Dictionary Literal
NSDictionary* literalDictionary = @{@1:@"first", @2:@"Second", @3:@"Third"};

They are not behaving like String literals. My question is what can be the reason that they have not introduced NSCFConstantArray class similar to NSCFConstantString? What will be the drawback to introduce a new class except backward compatibility?

Question author Saurav-nagpal | Source

Answer


1


This could have been implemented, but it probably wouldn't be very useful. For this to work everything in the array or dictionary would have to be a compile-time constant as well. This would be rather limiting - without any other changes you'd only be able to create arrays and dictionaries containing nothing but strings. The number literals are not compile-time constants either. Of course those could be implemented as compile-time constants too.

But this whole thing would not be very useful. Most of the time you use those literals to put some values only known at runtime into arrays or dictionaries. It's probably not worth to go through all the trouble to implement all that.

Answer author Sven

Tickanswer.com is providing the only single recommended solution of the question Why there is No constant NSArray Literal and NSDictionary Literal under the categories i.e objective-c , nsarray , foundation , . Our team of experts filter the best solution for you.

Related Search Queries:


You may also add your answer

Thanks for contributing an answer to Tick Answer!