CorePlot in Swift can not call “numberForPlot”

落花浮王杯 提交于 2019-12-06 07:47:23

Try declaring the datasource methods like this:

func numberOfRecordsForPlot(plot: CPTPlot!) -> UInt {}
func numberForPlot(plot: CPTPlot!, field: UInt, recordIndex: UInt ) -> AnyObject! {}

The signatures have to match the Objective-C declarations exactly or they won't be called.

numberForPlot is defined in the CPTPlotDataSource this way:

-(id)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;

The return type of id gets translated into Swift as AnyObject! -- if you change your method to this it should get called correctly:

func numberForPlot(plot:CPTPlot, fieldEnum:Int, index:Int) -> AnyObject! {
    println("numberForPlot")
    return self.dataForChart[index] as NSNumber
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!