In some programming language, there are two more operators in addition to the simple || and & &. these operators, which I will call them _orif and _andif, can now be used instead of && and || and they can help improve efficiency and avoid mistakes, since evaluating conditional stops as soon as the answer is clear.
For example, evaluating the following expression will stop halfway through (selectedSprite != nil): false. Thus, the rest of the conditional value will be ignored and never evaluated, this will prevent a fatal error in this case: fatal error: unexpectedly found nil while unwrapping an Optional valueand it will go up to the second expression, because obviously nil is not responding SpriteOwner().
if (selectedSprite != nil) &&
(selectedSprite.SpriteOwner().type == "Human")
{
println("a human selected")
}
I'm looking for a replacement && & in the above code snippet that can be used instead of a simple && operator, so if the first expression evaluates to false (with selectedSpritenil equal), then the second expression is ignored altogether (since it does not affect the result)
Question:
Is there such a statement &&?in swift? if the answer is no,
Is there a better way to do this instead of nested if statements, as I wrote here:
if (selectedSprite != nil)
{
if (selectedSprite.SpriteOwner().type == "Human")
{
println("a human selected")
}
}
if, , if nil .