i have a two deep if statement and i’m wondering if i can condense to a single if stmt:
if ([[myScrollView.subviews objectAtIndex:k] isKindOfClass:[UILabel class]])
{
if (((UILabel *)[myScrollView.subviews objectAtIndex:k]).tag >= i)
{
//code
}
}
i’m not sure if i can make it into:
if ([[myScrollView.subviews objectAtIndex:k] isKindOfClass:[UILabel class]] && ((UILabel *)[myScrollView.subviews objectAtIndex:k]).tag >= i)
since the second if condition is dependent on the first (if it is not a UILabel and doesn’t have a .tag value) can bad things happen?
You can combine them like that, yes. If the first statement fails then it fails the entire
ifstatement and doesn’t execute the 2nd part.For ease of reading I would probably write it like this though: