Arunabh Das
Arunabh Das

Reputation: 14392

Binary operator '!=' cannot be applied to operands of type 'NSError' and 'NilLiteralConvertible'

I have the following code :

if ((error) != nil) {
    print(error, terminator: "")
}

in my Swift program (converted to Swift 2 from Swift 1)

But Xcode is complaining

Binary operator '!=' cannot be applied to operands of type 'NSError' and 'NilLiteralConvertible'

What is the issue with the above line?

Upvotes: 2

Views: 1180

Answers (1)

Pavan Gandhi
Pavan Gandhi

Reputation: 1749

Simply try with following code and it works

if (error != []) 
{
    // do whatever u want
}

OR other option is to use try catch block available in swift 2.0

Upvotes: 1

Related Questions