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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:21:34+00:00 2026-05-27T03:21:34+00:00

NSMutableArray *noDup = [[NSMutableArray alloc]init]; NSMutableArray *dup = [[NSMutableArray alloc]init]; for (NSString *first in

  • 0
NSMutableArray *noDup = [[NSMutableArray alloc]init];
NSMutableArray *dup = [[NSMutableArray alloc]init];

for (NSString *first in newsmall)
{
    BOOL hasfound = NO;
    //NSLog (@"first %@", first);

    for (NSString *second in newbig) 
    {
        //NSLog (@"second %@", second);
        if ([second isEqualToString:first])
        {
            [dup addObject:first];
            hasfound = YES;
            break;
        }
    }

    if (!hasfound)
    {
        //NSLog (@"has not found %@", first);
        [noDup addObject:first];
    }
}

newsmall is a small array of only strings and newbig is a big array of only strings. The app shuts itself without any debug warning. NSLog showed “first” and “second”, but not “has not found”. How come?

  • 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-27T03:21:35+00:00Added an answer on May 27, 2026 at 3:21 am

    Oh, duhhhhh. I understand your problem now.

    Reverse the order in which your arrays are being compared. If you want to find which strings in newbig do not exist in newsmall, iterate across newbig first while looking to see which enumerated word in newbig exists in newsmall.

    The code looks like this (and only two lines of code have changed):

    NSMutableArray *noDup = [[NSMutableArray alloc]init];
    NSMutableArray *dup = [[NSMutableArray alloc]init];
    
    for (NSString *first in newbig)
    {
        BOOL hasfound = NO;
        //NSLog (@"first %@", first);
    
        for (NSString *second in newsmall) 
        {
            //NSLog (@"second %@", second);
            if ([second isEqualToString:first])
            {
                [dup addObject:first];
                hasfound = YES;
                break;
            }
        }
    
        if (!hasfound)
        {
            //NSLog (@"has not found %@", first);
            [noDup addObject:first];
        }
    }
    

    See the subtle difference?

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

Sidebar

Related Questions

NSMutableArray *tempMutableArray = [[NSMutableArray alloc] init]; if (street != NULL) { [tempMutableArray addObject:(NSString *)street];
NSMutableArray *insideArray = [[NSMutableArray alloc] init]; NSMutableArray *outsideArray = [[NSMutableArray alloc] init]; [insideArray addObject:@Hello
arr = [[NSMutableArray alloc]init]; [arr addObject:[NSNumber numberWithInt:4]]; [arr addObject:[NSNumber numberWithInt:45]]; [arr addObject:[NSNumber numberWithInt:23]]; [arr
NSMutableArray *myArray = [[NSMutableArray alloc] init]; MyClass *obj1 = [[MyClass alloc] init]; [myArray addObject:
NSMutableArray *a1 = [[NSMutableArray alloc] init]; NSMutableArray *a2 = [NSMutableArray array]; TempObj *obj =
-(NSMutableArray *)processResult:(NSArray*)matchArray removeString:(NSString *)removeStr{ NSString *newLink; NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[matchArray count]]; //doing
NSMutableArray*array = [[NSMutableArray alloc]init]; NSArray*Somearray = [NSArray arrayWithObjects:1st Object,2ndObject,3rd Object,4th object,5th Object,nil]; In the
Heres my array NSMutableArray *arrayTmp= [[NSMutableArray alloc] init]; I populate it like this double
data = [[NSMutableArray arrayWithCapacity:numISF]init]; count = 0; while (count <= numISF) { [data addObject:[[rouge_col_data
NSMutableArray *tempData=[[NSMutableArray alloc]init]; TBXMLElement * city = [TBXML childElementNamed:@city parentElement:root]; while(city!=nil){ if([TBXML valueOfAttributeNamed:@name forElement:city]!=nil){

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.