Jaimesh Patel Jaimesh Patel - 6 months ago 15
Swift Question

Binary operator '&&' cannot be applied to two 'Int' operands

I wanted to check for below values firstName and lastName. But Swift will not allowing me to access. It is giving error like "Binary operator '&&' cannot be applied to two 'Int' operands".

if firstName.length && lastName.length {

}

Answer

In Swift you cannot check for non-null like in C and Objective-C, you have to write

if firstName.length > 0 && lastName.length > 0 { }