2014-10-17 34 views
1

我试图在我的执行中使用下面的委托在swift(见下文)与 “不符合协议...”和错误消息,如“候选人有非匹配类型(PieChartView) - > Int“ 任何想法?斯威夫特:候选人有不匹配的类型

@protocol PieChartViewDataSource <NSObject> 

@required 
- (int)numberOfSlicesInPieChartView:(PieChartView *)pieChartView; 
- (double)pieChartView:(PieChartView *)pieChartView valueForSliceAtIndex:(NSUInteger)index; 
- (UIColor *)pieChartView:(PieChartView *)pieChartView colorForSliceAtIndex:(NSUInteger)index; 

未能迅速落实

func numberOfSlicesInPieChartView(pieChartView: PieChartView) -> Int { 
    return 3 
} 

func pieChartView(pieChartView: PieChartView, colorForSliceAtIndex index: Int) -> UIColor? { 
    return UIColor(rgba: "#FF0000") 
} 

func pieChartView(pieChartView: PieChartView, valueForSliceAtIndex index: Int) -> Double { 
    return 100/3; 
} 
+0

你可以给你正在使用的库或PieChartViewDataSource的协议源声明吗? – Pintouch 2014-10-17 10:14:19

回答

1
func numberOfSlicesInPieChartView(pieChartView: PieChartView) -> CInt { 
    return 32 
} 
func pieChartView(pieChartView: PieChartView, colorForSliceAtIndex index: UInt) -> UIColor { 
    return UIColor(red: 1.0, green: 0, blue: 0, alpha: 1) 
} 

func pieChartView(pieChartView: PieChartView, valueForSliceAtIndex index: UInt) -> Double { 
    return 100/3; 
} 

使用-> CInt而不是Int因为斯威夫特Int不能转换到C int。同Double - >CDouble

使用index: UInt而不是index: Int,因为NSUInteger无符号

+0

非常感谢你! – sonix 2014-10-20 08:10:01