0 votes
in Swift by
What is the use of double question mark “??” in swift?

1 Answer

0 votes
by

The double question mark “??” is a nil-coalescing operator, it is mainly a shorthand for the ternary conditional operator where we used to test for nil. A double question mark is also used to provide a default value for a variable.

stringVar ?? “default string”

This exactly does the common thing, if stringVar is not nil then it is returned, otherwise the “default string” is returned.

Related questions

0 votes
asked Nov 8, 2022 in Swift by SakshiSharma
0 votes
0 votes
asked Nov 7, 2022 in Swift by Robin
...