Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Crash: could not cast to 'Charts.PieChartData': in 2.3.0 when upgrading to XCode 8.0 #1609

Closed
LiftEd-Admin opened this issue Oct 5, 2016 · 2 comments

Comments

@LiftEd-Admin
Copy link

LiftEd-Admin commented Oct 5, 2016

Seems related to closed issue #410 (#410) but not fixed by d6cb47e

Error in console:

Could not cast value of type 'Charts.ChartData' (0x100e0e838) to 'Charts.PieChartData' (0x100e183e0).

Crash on line 182 of PieChartView.swift: private func calcAngles():
let yValueSum = (_data as! PieChartData).yValueSum

Error occurs on updated Charts CocoaPod to 2.3.0 and swift 2.3 when upgrading primarily Objective-C codebase from XCode 7 to XCode 8

Objective-C Code triggering this issue:

double resultForPercentage = somevalue;
ChartDataEntry *entry1 = [[ChartDataEntry alloc] initWithValue:resultForPercentage xIndex:0];
ChartDataEntry *entry2 = [[ChartDataEntry alloc] initWithValue:(100.0f - resultForPercentage) xIndex:1];
PieChartDataSet *set1 = [[PieChartDataSet alloc] initWithYVals:@[entry1,entry2]];

goalCell.graphView.data = [[ChartData alloc] initWithXVals:@[@"",@""] dataSets:@[set1]];

which then eventually calls: PieChartView.swift: private func calcAngles():
let yValueSum = (_data as! PieChartData).yValueSum

@pmairoldi
Copy link
Collaborator

You need to use PieChartData as the class instead of ChartsData so:

goalCell.graphView.data = [[PieChartData alloc] initWithXVals:@[@"",@""] dataSets:@[set1]];

@LiftEd-Admin
Copy link
Author

Confirmed that petester42's suggestion worked.

FYI: The code above worked fine in Charts 2.1.6, it was updating to XCode 8 + Swift 2.3 + Charts 2.3.0 that triggered this error. Glad it was a simple fix, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants