Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8843125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:08:26+00:00 2026-06-14T11:08:26+00:00

I thought the new notation works like this: someArray[5] turns into someArray[5] will actually

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:08:28+00:00Added an answer on June 14, 2026 at 11:08 am

    I have a better answer!

    This code will dynamically patch NSOrderedSet for versions of iOS that don’t support -objectAtIndexedSubscript:.

    #import <Foundation/Foundation.h>
    #import <objc/runtime.h>
    
    id PatchedObjectAtIndexedSubscript(id self_, SEL cmd_, NSUInteger index)
    {
        return [self_ objectAtIndex:index];
    }
    
    void PatchedSetObjectAtIndexedSubscript(id self_, SEL cmd_, id object, NSUInteger index)
    {
        return [self_ replaceObjectAtIndex:index withObject:object];
    }
    
    void SIPatchNSOrderedSet()
    {
        char types[6];
    
        if (!class_getInstanceMethod([NSOrderedSet class], @selector(objectAtIndexedSubscript:))) {
            sprintf(types, "@@:%s", @encode(NSUInteger));
            class_addMethod([NSOrderedSet class],
                            @selector(objectAtIndexedSubscript:),
                            (IMP)PatchedObjectAtIndexedSubscript,
                            types);
        }
    
        if (!class_getInstanceMethod([NSMutableOrderedSet class], @selector(setObject:atIndexedSubscript:))) {
            sprintf(types, "v@:@%s", @encode(NSUInteger));
            class_addMethod([NSMutableOrderedSet class],
                            @selector(setObject:atIndexedSubscript:),
                            (IMP)PatchedSetObjectAtIndexedSubscript,
                            types);
        }
    }
    

    At the start of your application (-application:didFinishLaunchingWithOptions: maybe) call SIPatchNSOrderedSet().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im new on this project and am going to write, what i thought was
I thought I would start a new question for this. I have a TCP
I thought I new this, but when I create an object out of an
I'm new to Laravel and thought it be cool to purchase the Codehappy ebook
I'm new to Django and thought I'd go through a few tutorials before branching
Starting a new rails project and we have a well-thought-out color palette, and want
I'm very new to web app development and I thought I would start with
I'm new to boost, and thought I'd try it out with some realistic deployment
I'm new here. I thought I could ask for some help here on my
So I thought I'd write my first codeigniter helper (still new to codeigniter somewhat).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.