Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple statements in a loop with if else

Tags:

objective-c

EDIT: Updated code to better reflect my problem

this code returns 9 strings to badDestination1

NSMutableArray* goodDestination1 = [NSMutableArray array];
NSMutableArray* badDestination1 = [NSMutableArray array];
NSMutableArray* badDestination2 = [NSMutableArray array];

for (NSString* item in sourceArray)
{
    if ([item rangeOfString:@"<b>"].location != NSNotFound)

        [goodDestination1 addObject:item];

    else {
        [badDestination1 addObject:item];
        //[badDestination2 addObject:@"Title"];
    }
}

This code returns 1 value to badDestination2

for (NSString* item in sourceArray)
    {
        if ([item rangeOfString:@"<b>"].location != NSNotFound)

            [goodDestination1 addObject:item];

        else {
            //[badDestination1 addObject:item];
            [badDestination2 addObject:@"String"];
        }
    }

anyone know whats going on? Seems like the "String" might be getting rewritten in the same location on the array maybe?

like image 754
S-T-R-E-G-A Avatar asked Dec 13 '25 12:12

S-T-R-E-G-A


1 Answers

Looks like you're missing the braces {} after the else.

else {
  [arrayDestinationBad1 addObject:item]; 
  [arrayDestinationBad2 addObject:@"String"]; 
}
like image 148
Michael Myers Avatar answered Dec 16 '25 09:12

Michael Myers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!