IntValue ?? 0 == -1? “-”: “+” What does this mean?

  • A+
Category:Languages

I am importing price information and adding + or -.

I put the title code in print () and it works but I do not know what it means.

print("/(IntValue ?? 0 == -1 ? "-" : "+")") 

Please explain it briefly to me.

 


The variable IntValue is an optional, which means its either an Integer or nil. IntValue ?? 0 means that if IntValue exists, then use the value of IntValue. If IntValue is nil, then use the value 0. Next, compare that value with -1. If that value is equal to -1, then print -. If that value does not equal -1, then print +.

Here's equivalent code with only if statements:

var defaultInt = 0 if IntValue == nil {     defaultInt = IntValue } if defaultInt == -1 {     print("-") } else {     print("+") } 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: