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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:48:04+00:00 2026-05-26T01:48:04+00:00

I have an object called brain brain has 8 properties that contain an Animal

  • 0

I have an object called brain

brain has 8 properties that contain an “Animal” object.

brain.animal1,
brain.animal2,
animal3,
…
brain.animal8

I then have three other properties called

brain.selectedAnimal1, brain.selectedAnimal2, brain.selectedAnimal3

What I would like to do is loop through all of the 8 animal properties… and if one of those animal properties matches up with selectedAnimal1 property, i want to set the animal property to nil.

I only want to set one animal property to nil (i.e. if two of the animal properties match the selectedAnimal1 property I only want the first one to be set to nil, not both)

Then I want to do the same loop but compare with selectedAnimal2 and selectedAnimal3 properties and set animal properties to nil if they match with a selectedAnimal.

Can anyone help with this? I’m just not quite good enough yet with objective-c to get this to work without writing about 50 lines of code

So to recap… I start with 8 animal properties and would like to end with 5 animal properties (3 being set to nil)

Thanks in advance,

  • 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-26T01:48:05+00:00Added an answer on May 26, 2026 at 1:48 am

    It seems very non-flexible and non-extendible to have animal1, animal2, … and selectedAnimal1, selectedAnimal2, …

    You should really look into using collections (NSMutableArray or NSMutableSet), say animals and selectedAnimals, then you can loop through you animal objects using fast enumeration:

    for (Animal* animal in animals) {
        for (Animal* selectedAnimal in selectedAnimals) {
            /* Do checks */
        }
    }
    

    If you find an animal which is in both you can remove it from animals. Careful not to change a mutable array while enumerating it, you’ll get crashes. I think you should use NSMutableSet (which have union, minus operators and so on, making it easy to subtract common elements from one set).

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

Sidebar

Related Questions

I have an object called Person that has the following properties: int id; Name
I have an object that has properties of another object and one called DataValue
I have an object called Layer that has some attributes and some methodes. i
I have an object called Document that has a one-to-many relationship with DocumentPersonCc. I
i have business object called TeamMaster , in which i define three properties,Id,Name &
i have an object called Person . It has properties First, Last, Age ,
I have an object called Result<T> that has a constructor which accepts an argument
I have an object called human and that object has a field called job.
I have an object called users that I use to store user objects that
I have an object called Contact. A Contact has a relationship with a set

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.