what's the purpose of double question mark in swift
IosSwiftIos 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
.