Can't Use Literal Syntax in NSBundle infoDictionary

Originator:sethfri
Number:rdar://19949629 Date Originated:02/24/2015
Status:Closed Resolved:Yes
Product:iOS SDK Product Version:Xcode 6.2 beta 5
Classification:Other Bug Reproducible:Always
 
Summary:
[NSBundle mainBundle].infoDictionary["exampleKey"] = @"exampleValue" throws an exception. It doesn't make any sense that this one NSDictionary can't use literal syntax even though every other one can.

Steps to Reproduce:
See Description. Just write that line anywhere in an iOS app.

Expected Results:
Literal syntax should be possible on all NSDictionarys

Actual Results:
Expected method to write dictionary element not found on object of type 'NSDictionary *'

Version:
Xcode 6.2 beta 5

Notes:


Configuration:
iOS simulator

Comments

Apple Developer Relations

This issue behaves as intended based on the following:

The error message is correct. Assigning to a subscript of that dictionary is invalid because the type of the dictionary is not NSMutableDictionary *. You should also get a compiler warning (or error) if you send it a setObject:forKey: message.

You can use literal/subscript syntax on it just fine—but only for reading.

Furthermore, since we declare the method’s return type as NSDictionary *, any attempt to mutate it is unsupported. Even if you have personally seen it return a mutable dictionary, we do not guarantee that, and so you must not rely on it.

(And I’m assuming the omission of the @ on the string literal in the subscript was an accident.)

Please update your bug report to let us know if this is still an issue for you.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!