I have a Foundation macOS App written in Swift. I'm trying to use SwiftUI Chart View in NSViewcontroller (tutorial here) but it's seems import Charts
doesn't recognized and I obtain the error Cannot find 'Chart' in scope
and Cannot find 'LineMark' in scope
.
Any idea about the issue and how to resolve it ?
EDIT n.1
I've changed deployment target to macOS 13.0+ but still have the same error.
EDIT n.2
I've tried with this sintax (using foreach inside construction closure) but still have the same error.
var body: some View {
Chart {
ForEach(entries) { entry in
LineMark(x: .value("Time", entry.time),
y: .value("Temp", entry.temp))
.foregroundStyle(.red)
}
}
}
Are you using Charts 3rd party library by any chance in your project?
This one? https://github.com/danielgindi/Charts
if so work around needs to be renaming Charts library to DGCharts, they are already working on it but this issue explains it
https://github.com/danielgindi/Charts/issues/4897
my solution would be:
or if you are using cocoa pods you can use
pod 'DGCharts', :git => 'https://github.com/danielgindi/Charts.git' , :branch => 'release/5.0.0'