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 8961479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:54:09+00:00 2026-06-15T15:54:09+00:00

What, if any, NSSet and NSOrderedSet operations can one perform with the new Objective-C

  • 0

What, if any, NSSet and NSOrderedSet operations can one perform with the new Objective-C collection literals?

For NSArray, NSDictionary, and NSNumber, see here.

FWIW, this Big Nerd Ranch Post says the indexing syntax is supposed to work for NSOrderedSet. But in my tests it does not. And I haven’t been able to find anything about creating ordered sets.

  • 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-15T15:54:11+00:00Added an answer on June 15, 2026 at 3:54 pm

    There is no Objective-C literal syntax for NSSet. It doesn’t really make sense to use index subscripting to access NSSet elements, although key-based subscripting might. Either by wrapping or subclassing, you could add your own.

    (Correction):
    Originally I had thought NSOrderedSet wasn’t supported either, but it turns out that using index subscripting is supported, but there doesn’t seem to be a way of initializing an NSOrderedSet with the literal syntax. However, you could use initWithArray: and pass a literal array:

    NSMutableOrderedSet* oset = [[NSMutableOrderedSet alloc] initWithArray: 
        @[@"a", @"b", @"c", @"d", @42]];
    
    oset[2] = @3;
    NSLog(@"OrderedSet: %@", oset);
    

    Outputs:

    OrderedSet: {(
        a,
        b,
        3,
        d,
        42
    )}
    

    According to this excellent post by Mike Ash, you can add the methods that are used to support indexed subscripting to your own objects.

    - (id)objectAtIndexedSubscript:(NSUInteger)index;
    - (void)setObject: (id)obj atIndexedSubscript: (NSUInteger)index;
    

    And similar methods for object-based keying:

    - (id)objectForKeyedSubscript: (id)key;
    - (void)setObject: (id)obj forKeyedSubscript: (id)key;
    

    Thus you could implement a wrapper (or with a bit more work, subclass it) around an NSSet and provide key-based retrieval. Cool!

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

Sidebar

Related Questions

Any idea on how can I track users bookmarking event? I want to find
Any Access guru's out there that can help me out? Trying to figure out
Any way to declare a new variable in F# without assigning a value to
I can detect single/double-taps in specific views with: NSSet *myTouches = [event touchesForView:mySpecificView.view]; but
Is there any downside to using NSSet as key in NSMutableDictionary , any gotchas
I'm working on a music app, so I can't really approve any latancy. I'm
Any way to realize emacs keybind on Qt Creator (QTC)? Some possibilities: emacskeys but
Any phone numbers that begin with these ranges correct: ex: 772123322 The length is
Any best way to run the jasmine HTML reporter with browserify styled code? I
Any tips on making the following option elements draggable? <select id=expenseSelect multiple=multiple style=height:200px> <option

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.