Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inequality operator(!= equivalent) in swift

Tags:

swift

We check String equality in swift using "==".But how to use != (In objective c) equivalent in swift?I want to check str1!=str2.But compiler is suggesting me to delete '!' character.

like image 673
nik Avatar asked Sep 02 '16 10:09

nik


1 Answers

The not equal to != operator is the same in Swift as in Objective C, because it is a standard C comparison operator

According to the Swift documentation for Basic Operators:

Swift supports all standard C comparison operators:

Equal to (a == b)

Not equal to (a != b)

The reason your example doesn't work, is because you must add whitespace:

str1!=str2

should be

str1 != str2
like image 139
Daniel Avatar answered Oct 22 '22 02:10

Daniel