0

I'm running some code that does a [NSDictionary objectForKeyedSubscript:] and it's crashing on iOS 5, but not iOS 6. I am using xcode 4.5.2 and compiling against the iOS 6.0 SDK.

I assumed that this would work on iOS 5 since it's just a compiler feature? Am I wrong about that? I can just write my own versions of those functions, but I'm worried that something else is wrong since I would expect it to work.

Roger Gilbrat
  • 3,755
  • 5
  • 34
  • 58

3 Answers3

3

NSDictionary reference for IOS in Apple developer

Available in iOS 6.0 and later.

Community
  • 1
  • 1
Giuseppe Mosca
  • 1,323
  • 12
  • 18
3

OK, I'm going to answer my own questions, although I don't completely understand why it was failing.

Using objectForKeyedSubscript: and the like works fine running in iOS 5 (as long as it was compiled against the iOS 6 SDK).

The problem was I named a function +(void)load and making objectForKeyedSubscript: calls in this function causes an assert due to the method not being found.

This was an naming error on my part because the load method is called before the App is fully running. I have changed the name of my function and all is well.

I assume +load is being called before something with NSDictionary is fully inited. Odd that it works under iOS 6 and just not iOS 5.

Maybe that's not odd.

Roger Gilbrat
  • 3,755
  • 5
  • 34
  • 58
  • 1
    The thing is that these functions are compiled into iOS 6, but in iOS 5 they are added in a "load" function of an internal class. If that order were wrong (the order is not guaranteed) then your class would try to use it before the runtime actually added it. Here are a few details -> http://www.mikeash.com/pyblog/friday-qa-2012-06-22-objective-c-literals.html#comment-c4ce71c3d04c25f8f40c2b5c5e130a29 – borrrden May 25 '13 at 02:35
0

There is a workaround for pre-iOS6 SDKs

Checkout question here: Is there any way to get the neat Objective-C literal indexing feature in Xcode 4.4?

Community
  • 1
  • 1
amleszk
  • 6,192
  • 5
  • 38
  • 43