2014-10-17 38 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