3

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?

2
  • 1
    How many items are there in stringSource? If the count is 1 then it will surely only be called once. Commented Feb 9, 2010 at 15:56
  • I am positive there are at least 9 items being put into arrayDestinationBad1 Commented Feb 9, 2010 at 16:07

1 Answer 1

5

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

else {
  [arrayDestinationBad1 addObject:item]; 
  [arrayDestinationBad2 addObject:@"String"]; 
}
Sign up to request clarification or add additional context in comments.

10 Comments

He says it only gets called once (obviously implying he wants it called more often). Without the braces it /should/ get called every time through the loop.
@Matthew: That's true, but what else could be the problem with that code?
I don't know, but adding the braces can only make it run less (<=) often. :)
Perhaps it was mis-copied and that statement is actually outside the loop. That's the only thing I can think of.
So it was a dictionary and not an array? Tsk, tsk. ;)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.