what's the purpose of double question mark in swift

IosSwift

Ios Problem Overview


I have seen such function:

public func highlightValues(highs: [ChartHighlight]?)
{
    // set the indices to highlight
    _indicesToHightlight = highs ?? [ChartHighlight]();

    // redraw the chart
    setNeedsDisplay();
}

What's the purpose of ?? here? I searched, but it seems searching ?? is hard to find a proper answer.

Ios Solutions


Solution 1 - Ios

It is called nil coalescing operator. If highs is not nil than it is unwrapped and the value returned. If it is nil then [ChartHighlight]() returned. It is a way to give a default value when an optional is nil.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWingzeroView Question on Stackoverflow
Solution 1 - IosmustafaView Answer on Stackoverflow