I'm using the ios library Charts (https://github.com/danielgindi/Charts)
There's a delegate function declared chartValueSelected
, which gives me back entry: ChartDataEntry
.
So I get the entry
, with it's data
, declared as var data: AnyObject?
print(entry.data)
> Optional(Optional(<MyProject.Stop: 0x6000002c5cc0> (entity: Stop; id: 0xd00000000c980010 <x-coredata://5F54CCEC-11FB-42F1-BDFE-30F7F7E18614/Stop/p806> ; data: { ... })))
print(type(of: entry.data))
> Optional<AnyObject>
That's wierd? I assigned it a non optional? Well, that might be a bug in the library, but I should atleast be able to access it?
guard let e = stopEntry as? Stop else {
continue
}
yVal.append(BarChartDataEntry(value: e.duration!.doubleValue, xIndex: i, data: e))
Well, we're fine with the ??
double optional.. But what? Why cant we unwrap it?
if let hasObject = entry.data {
print("We have object: \(type(of: hasObject))")
> We have object: _SwiftValue
if let stopObject = hasObject as? Stop {
print("We have a stop object!!") // Doesnt come here
}
}
More things that doesnt work are:
if let s = entry.data, let b = s as? Stop {
// Not executed here either
}