Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Hamza Ansari
34 PointsHow do I re-write this code using Swift?
I need to be able to write this code in Swift so I can call the proper classes for a pie graph I'm trying to create for my app. Does anyone know how to re-write this in Swift? Also how would I add values, like number of slices and values for each slice? Thank you.
- (NSUInteger)numberOfSlicesInPieChart:(XYPieChart *)pieChart {
return self.values.count;
}
- (CGFloat)pieChart:(XYPieChart *)pieChart valueForSliceAtIndex:(NSUInteger)index {
NSNumber* value = self.values[index];
return value.doubleValue;
}
- (UIColor *)pieChart:(XYPieChart *)pieChart colorForSliceAtIndex:(NSUInteger)index;
- (NSString *)pieChart:(XYPieChart *)pieChart textForSliceAtIndex:(NSUInteger)index;
2 Answers
Patrick Cooney
12,216 PointsBecause the XYPieChart code doesn't offer Swift interfaces it would be a pain to re-write in pure Swift. I would suggest you take a look at Apple's documentation on how to use Swift with Cocoa and Objective-C.
agreatdaytocode
24,757 PointsI found a line chart on GitHub.