Purpose of ?? in Swift -
this question has answer here:
- ?? operator in swift 4 answers
can explain advantage of writing ??
.would great if possible explain below code snippet how improve code?
import foundation var samplestring:string? print(samplestring ?? "nil")
thanks in advance.
from apple documentation:
the nil-coalescing operator (a ?? b) unwraps optional if contains value, or returns default value b if nil. expression of optional type. expression b must match type stored inside a.
in case if samplestring
nil return default string containing text "nil".
Comments
Post a Comment