I have a library that was compiled against Apple's LLVM 4.2 compiler (Base SDK 6.1). In it there is object subscripting.
Imagine that my library has only one class with one method. That method does this:
NSLog(@"****** preTests");
NSDictionary *dictTest = @{ @1 : @1 };
NSLog(@"Initialized Dictionary");
NSArray *arrayTest = @[ @1, @2, @3 ];
NSLog(@"Initialized Array");
NSLog(@"****** arrayTest[1] = %@", arrayTest[1]); // First use of subscripting
NSLog(@"****** dictTest[@1] = %@", dictTest[@1]);
Now I create a new project and link this library in. In my application delegate, I call this method. I compile this application with the GCC LLVM 4.2 compiler. It compiles and links fine.
This application will run without error on iOS 6+. This application will crash on iOS 5 at the "First use of subscripting" (above).
2013-07-03 09:15:51.050 GCCTest[167:707] -[__NSArrayI objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x381fb0
Compile it with the Apple LLVM 4.2 compiler and it will run normally.
objectAtIndexedSubscript:
is a method made publicly available in iOS 6 and it is my understanding that it what the syntactic sugar of myArray[0]
gets translated to.
Can someone help me understand why I see a crash with GCC and not Apple with iOS 5? I'm guessing it has to do with some macros somewhere... Could this be made not to crash with GCC without editing the code of my library?