I've faced an unknown type in Show Quick Help section in Playground.
I've opened Show Quick Help section to look at the type of first which is the property of the Array.
The question is, what is the double marks at the end of the type?
This is familiar
Double?
Apple - Optional
Unknown type
Double??

If double question marks are used , it is clearly to emphasise something in return, usually from the shock of the previous thing said, to express a strong emotion. For example, if I said:- 'My dog just died' Someone may reply. 'Really??'
In general, avoid what could be called aggressive punctuation: the combination of multiple consecutive exclamation points and/or question marks (instead of the usual allotment of one) to demonstrate anger, irritation, or urgency. In business communications, such punctuation can be inflammatory or offensive.
A question mark indicates to your readers that your sentence should be read as an inquiry. It is the end mark used in interrogative sentences. Question words like who, when, where, why, what, which, and how indicate that a sentence is a question.
In simplest way, two question marks are called "Coalescing Operator", which returns first non null value from the chain. e.g if you are getting a values from a nullable object, in a variable which is not nullable, then you can use this operator.
Double?? is shorthand notation for Optional<Optional<Double>>, which is simply a nested Optional. Optional is a generic enum, whose Wrapped value can actually be another Optional and hence you can create nested Optionals.
let optional = Optional.some(2)
let nestedOptional = Optional.some(optional)
The type of nestedOptional here is Int??.
For your specific example, item.first is Double??, since item itself is of type [Double?] and Array.first also returns an Optional, hence you get a nested Optional.
Your compactMap call on data achieves nothing, since you call it on the outer-array, whose elements are non-optional arrays themselves. To filter out the nil elements from the nested arrays, you need to map over data and then call compactMap inside the map.
let nonNilData = data.map { $0.compactMap { $0 } } // [[100, 35.6], [110, 42.56], [120, 48.4], [200]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With