I thought the new notation works like this:
someArray[5] turns into
someArray[5] will actually turn into [someArray objectAtIndexedSubscript:5]
However, in NSArray.h and NSOrderedSet.h I saw this:
- (id)objectAtIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0);
So, objectAtIndexedSubscript is only available for IOS6.
I experimented making this simple code:
NSArray * someArray =@[@"hello",@"World",@"World"];
NSOrderedSet * someOS = [NSOrderedSet orderedSetWithArray:someArray];
PO(someArray);
PO(someOS);
PO(someArray[0]);
PO(someOS[0]); //Exception thrown here
The code break at someOS[0]
-[__NSOrderedSetI objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x8b1fac0
in BOTH NSArray and NSOrderedSet, there is a text NS_AVAILABLE(10_8, 6_0);
Yet it doesn’t break on NSArray yet break on NSOrderedSet. Why?
Bonus: How do I make it work for NSOrderedSet too with category (need to check that it’s not already defined)
I have a better answer!
This code will dynamically patch
NSOrderedSetfor versions of iOS that don’t support-objectAtIndexedSubscript:.At the start of your application (
-application:didFinishLaunchingWithOptions:maybe) callSIPatchNSOrderedSet().