开发者

Multiple statements in a loop with if else

开发者 https://www.devze.com 2022-12-19 11:45 出处:网络
EDIT: Updated code to better reflect my problem this code returns 9 strings to badDestination1 NSMutableArray* goodDestination1 = [NSMutableArray array];

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>"].locatio开发者_Python百科n != 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?


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

else {
  [arrayDestinationBad1 addObject:item]; 
  [arrayDestinationBad2 addObject:@"String"]; 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号