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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:23:56+00:00 2026-06-06T20:23:56+00:00

Surely an ordered set is a more-specific case of a set, so why does

  • 0

Surely an ordered set is a more-specific case of a set, so why does NSOrderedSet inherit from NSObject rather than NSSet?

  • 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-06T20:23:58+00:00Added an answer on June 6, 2026 at 8:23 pm

    I went through the interface of NSSet and you’re right, ordered sets appear to satisfy the Liskov substitution principle and could therefor inherit from NSSet.

    There is one little method that breaks this: mutableCopy. The return value of mutableCopy must be an NSMutableSet, but NSMutableOrderedSet should inherit from NSOrderedSet. You can’t have both.

    Let me explain with some code. First, let’s look at the correct behaviour of NSSet and NSMutableSet:

    NSSet* immutable = [NSSet set];
    NSMutableSet* mutable = [immutable mutableCopy];
    
    [mutable isKindOfClass:[NSSet class]]; // YES
    [mutable isKindOfClass:[NSMutableSet class]]; // YES
    

    Now, let’s pretend NSOrderedSet inherits from NSSet, and NSMutableOrderedSet inherits from NSOrderedSet:

    //Example 1
    NSOrderedSet* immutable = [NSOrderedSet orderedSet];
    NSMutableOrderedSet* mutable = [immutable mutableCopy];
    
    [mutable isKindOfClass:[NSSet class]]; // YES
    [mutable isKindOfClass:[NSMutableSet class]]; // NO (this is the problem)
    

    What if NSMutableOrderedSet inherited from NSMutableSet instead? Then we get a different problem:

    //Example 2
    NSOrderedSet* immutable = [NSOrderedSet orderedSet];
    NSMutableOrderedSet* mutable = [immutable mutableCopy];
    
    [mutable isKindOfClass:[NSSet class]]; // YES
    [mutable isKindOfClass:[NSMutableSet class]]; // YES
    [mutable isKindOfClass:[NSOrderedSet class]]; // NO (this is a problem)
    

    In Example 1, you wouldn’t be able to pass an NSOrderedSet into a function expecting an NSSet because the behaviour is different. Basically, it’s a backwards compatibility problem.

    In Example 2, you can’t pass an NSMutableOrderedSet into a function expecting an NSOrderedSet because the former doesn’t inherit from the latter.

    All of this is because NSMutableOrderedSet can’t inherit from both NSMutableSet and NSOrderedSet because Objective-C doesn’t have multiple inheritance. The way to get around this is to make protocols for NSMutableSet and NSOrderedSet, because then NSMutableOrderedSet can implement both protocols. I guess the Apple developers just though it was simpler without the extra protocols.

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

Sidebar

Related Questions

I have coded the next function. But surely someone has a more elegant way
My question is surely banal but i can't set up an sql query that
Surely a 0d array is scalar, but Numpy does not seem to think so...
How can I make a folder that does things. Surely dropbox knows when a
Surely there is a way to store a date value prior than 1-1-1900 in
an example code what I try to do will surely do better than my
Surely you are familiar with UML class diagrams and object diagrams and their relationships.
I have what must surely be a fairly common documentation need... I'm implementing a
Surely I'm missing something pretty obvious... I have a field that is decimal with
Surely, surely, surely there is a way to configure the .Net HttpWebRequest object so

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.