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

  • Home
  • SEARCH
  • 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 6337857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:19:54+00:00 2026-05-24T19:19:54+00:00

Two related questions: When you use [NSSet setWithArray:] , does it remove duplicate object

  • 0

Two related questions:

  1. When you use [NSSet setWithArray:], does it remove duplicate object for you automatically?

  2. How can you tell NSSet exactly what you want “duplicate” to mean? I.e. if you have a bunch of “College course” objects, each with a name and section number, and you wanted to transfer to an NSSet, keeping only one of each college course for a given name (for example, if you had three sections of Calculus, how would you tell it to only keep one section of calculus, even if their section numbers are different, so they’re not perceived as identical by default).

Thanks! Let me know if that question was unclear at all. I was having trouble figuring out a way to word it.

Edit: This question is specific to NSManagedObjects, whose isEqual: method cannot be overridden.

  • 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-05-24T19:19:55+00:00Added an answer on May 24, 2026 at 7:19 pm
    1. From the documentation:

      If the same object appears more than once in array, it is added
      only once to the returned set.

    2. Equality is determined here as throughout Cocoa with the -isEqual: method (and the -hash method). If you want two custom objects to be considered equal, you should override these appropriately, and you must override both. These are generally used so that objects that really are equivalent and generally interchangeable (but are separate objects) can be seen as such. In your example, it sounds like the college course objects really are “different” (ie, they represent different classes, even if they might share the same overall “calculus” topic), so it seems problematic to call those object instances “equal” if this is a large scale project/code base. In your case, you might consider adding the object to the set one by one and do your own comparisons as you add to make sure you get one of each “topic”.

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

Sidebar

Related Questions

Two related questions in one: Can Clojure's core.logic module perform arithmetic, logical comparison, etc,
Okay, these two related questions are in reference to Railscast #21 : I'm having
Here are two questions related to modifying the data source for strongly typed dataset
I'm narrowing in on an underlying problem related to two prior questions. Basically, I've
Here are two different questions but I think they are related. When using Git,
I have two related tables in my database: Page and Tag. One Page can
I have two questions related to function objects and function pointers, Question : 1
I've looked through all the related questions with two or three different titles and
I have actually two questions but they are kind of related so here they
I have two related questions concerning NSAutoreleasePool. Between declaring the pool and draining it,

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.