编辑:更新代码以更好地反映我的问题
此代码返回9个字符串给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"];
}
}
Run Code Online (Sandbox Code Playgroud)
此代码向badDestination2返回1个值
for (NSString* item in sourceArray)
{
if ([item rangeOfString:@"<b>"].location != NSNotFound)
[goodDestination1 addObject:item];
else {
//[badDestination1 addObject:item];
[badDestination2 addObject:@"String"];
}
}
Run Code Online (Sandbox Code Playgroud)
有谁知道发生了什么?好像"String"可能会在阵列上的相同位置被重写?
看起来你错过了{}后面的大括号else.
else {
[arrayDestinationBad1 addObject:item];
[arrayDestinationBad2 addObject:@"String"];
}
Run Code Online (Sandbox Code Playgroud)