I'm attempting to make Swift Chart to work. I have this struct that Xcode says doesn't conform to Plottable. I checked protocol spec and it expect Double, String or Date. Id and Year therefore do not conform. The problem is that even when remove id and year from the struct, Xcode continues to say it doesn't conform to Plottable, and I have no idea why. Hours of searching, trying, and I couldn't make it work.
struct InvestmentData: Identifiable, Plottable {
var id: Int { year }
let year: Int
let principal: Double
let withReinvestment: Double
let withoutReinvestment: Double
let profit: Double
}
Xcode suggests adding protocol stubs, but I have no idea what to do with it.
typealias PrimitivePlottable = <#type#>
I would appreciate any pointers.
Tried:
- Removing id and year altogether
- Tried writing extension for non-Doubles, but couldn't make it work
- Tried changing everything to Double - still says doesn't conform
- Tried making new struct with just one var - it doesn't conform either
Do you really need to use
Plottablein your implementation? The struct can be used directly in a chartAlthough it will look much better with a
Stringas the x value type