Home:ALL Converter>Difference between error = error vs error != nil

Difference between error = error vs error != nil

Ask Time:2016-10-23T18:07:51         Author:Tarvo Mäesepp

Json Formatter

I would like to know is there big difference between

if let error = error{} vs if error != nil? Or is it just how people are different, like how they express themselves in code?

For example if I take this code:

user?.delete { error in
  if let error = error {
     print(error)                        
} else {

}

Because I can do the same like this and the output is the same:

user?.delete { error in
  if error != nil {
     print(error)
}else{

}

The only difference I can see other than "people are different" is that if I do not print error it would be better to use if error != nil because otherwise it would be declaring variable you do not use. Am I right?

Author:Tarvo Mäesepp,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40201737/difference-between-error-error-vs-error-nil
yy