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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:20:46+00:00 2026-06-14T09:20:46+00:00

I have an array of objects, each containing a bool value with yes or

  • 0

I have an array of objects, each containing a bool value with yes or no. I want to copy all objects with bool YES to another array. How can i do that? i have considered filtering the array using a predicate or integrating it in a for-loop, but i cant seem to get it right.

I need something like this:

for (BOOL* opslag_Set in [dataSource allKeys]){
    NSArray *array = [dataSource objectForKey:opslag_Set];
    for (int j = 0; j < [array count]; j++) {
        if ([[array objectAtIndex:j] isEqualToString:@"YES"]) {
            add object to another array;
        }
    }
}

First object of my array:

    },
    {
    Dato = "2012-11-07 16:20:57 +0000";
    Forfatter = "Vej 51, st. tv.";
    Indhold = "Referat af beboerm\U00f8de";
    "Opslag_set" = 0;
    Overskrift = "Beboerm\U00f8de";
    Prioritet = 0;
    Svar =         (
                    {
            Dato = "2012-11-07 16:23:07 +0000";
            Forfatter = "6. tv.";
            Indhold = "Fedt fedt fedt";
        }
    );
},
  • 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-14T09:20:47+00:00Added an answer on June 14, 2026 at 9:20 am

    You will have to use NSNumber in order to store the bools in an array.

    Assuming your boolean array is called boolArray, the code to get an array with only YES would be something like this:

    NSMutableArray* temp = [NSMutableArray new];
    for (NSNumber* value in boolArray)
    {
        if ([value boolValue])
        {
            [temp addObject:[NSNumber numberWithBool:YES]];
        }
    }
    

    However, why are you trying to do this? This will return an array with a certain number of elements that are all the same. You could just count the number if that’s what you want. The other thing I can think of is that you have an object with a bool property, in which case you can easily adapt the code above.

    EDIT: OK, let’s assume that we have an object called MyDataObject that has a bool property – NSNumber* boolProperty. Here is the code:

    NSMutableArray* temp = [NSMutableArray new];
    for (MyDataObject* value in boolArray)
    {
        if ([value.boolProperty boolValue])
        {
            [temp addObject:value];
        }
    }
    

    This should work for what you are doing. temp will reference the original objects – they are not being copied.

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

Sidebar

Related Questions

I have a 2D array containing all the Piece objects, each an instance of
I have an array of Objects, each containing a Location and a Links array
I have a mutable array that has about 100 objects in it and each
I have an array of objects and I want to add another object just
I have several string each containing a JSON representation of an array of objects.
I have an array of Password objects, each containing a tag , a username
I have an array containing objects that I need to sort, and remove duplicates
I have an array (items) of custom class objects (catalogItem) each catalogItem has various
I have an array of objects . Each object has an attribute we'll call
I have an array of Card objects (NSObjects), each with a field called tags

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.