With the new update to Xcode 7.3, a lot of issues appeared related with the new version of Swift 3. One of them says "C-style for statement is deprecated and will be removed in a future version of Swift" (this appears in traditional for
statements).
One of this loops has more than one condition:
for i = 0; i < 5 && i < products.count; i += 1 {
}
My question is, is there any elegant way (not use break
) to include this double condition in a for-in loop of Swift:
for i in 0 ..< 5 {
}
Here’s a simple solution:
One more example. Loop through all UILabel in subviews:
It would be just as you're saying if you described it out loud:
That said, I suspect you really mean:
which is less error-prone than anything that requires subscripting.
It's possible you actually need an integer index (though this is rare), in which case you mean:
Or you could even get a real index if you wanted with:
You can use
&&
operator withwhere
condition likeAnother way to do so would be like this