Is objectAtIndexedSubscript available in IOS5?

前端 未结 4 1567
慢半拍i
慢半拍i 2021-01-03 09:25

The documentation says it\'s available in MacOS 1.08.

So what\'s the story? What about for iOS5?

It\'s a very important selector because self[5] will actuall

相关标签:
4条回答
  • 2021-01-03 09:52

    No, only since iOS 6 unfortunately.

    Apple has separate documentations for the OS X and the iOS APIs. You have to check the right one: objectAtIndexedSubscript:.

    Availability
    Available in iOS 6.0 and later.

    0 讨论(0)
  • 2021-01-03 09:59

    I look at the NSOrderedSet.h file and I saw this:

    - (id)objectAtIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0);
    

    So it doesn't work for IOS5.

    0 讨论(0)
  • 2021-01-03 10:03

    If you need your code to run on iOS 5, you'll need to replace

    myOrderedSetOfHilariousAcronyms[2] = @"ROFL";
    

    with

    [myOrderedSetOfHilariousAcronyms setObject:@"ROFL" atIndex:2];
    
    0 讨论(0)
  • 2021-01-03 10:04

    While objectAtIndexedSubscript: is not available previous to iOS 6, NSArray and NSDictionarysubscripting is available. That means that you can use syntax like this:

    myArray[2] = @"thingie";
    myDictionary[@"roger"] = @"barry";
    

    And it will deploy back to iOS 4.

    However NSOrderedSet subscripting will not work on iOS 5 and previous. For that, you will need to provide a category that redirects objectAtIndexedSubscript: calls to objectAtIndex:.

    Addendum: Apple's docs for NSMutableOrderedSet are also incorrect. It states that index subscripting does an insert, when in reality is does a replace (as one would expect).

    0 讨论(0)
提交回复
热议问题