112

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.

Wingzero
  • 9,644
  • 10
  • 39
  • 80

1 Answers1

176

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.

mustafa
  • 15,254
  • 10
  • 48
  • 57