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?
According to the "Objective-C Feature Availability Index", NSArray
subscripting requires at least LLVM Compiler 4.0.
Starting with iOS 6, NSArray
has a objectAtIndexedSubscript:
method. For iOS 5,
this method is supplied by the static Arclite
library that is linked into the application
(see e.g. How to enable the new Objective-C object literals on iOS? and the links given in the answer).
But that is a Clang only feature, GCC does not support ARC.
So I do not see how you could use array subscripting if the main application is compiled and linked with GCC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With