JCode
JCode

Reputation: 1878

Core Plot with swift getting error : "Missing Argument for Parameter ‘frame’ in call"

I am trying to use core plot with swift and I feel very close except for one error. My code so far is :

class ViewController: UIViewController, CPTPlotDataSource {
    @IBOutlet weak var graphView: CPTGraphHostingView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // create graph
        var graph = CPTXYGraph(frame: CGRectZero)
        graph.title = "Hello Graph"
        graph.paddingLeft = 0
        graph.paddingTop = 0
        graph.paddingRight = 0
        graph.paddingBottom = 0
        // hide the axes
        var axes = graph.axisSet as CPTXYAxisSet
        var lineStyle = CPTMutableLineStyle()
        lineStyle.lineWidth = 0
        axes.xAxis.axisLineStyle = lineStyle
        axes.yAxis.axisLineStyle = lineStyle

        // add a pie plot
        var pie = CPTPieChart()
        pie.dataSource = self
        pie.pieRadius = (self.view.frame.size.width * 0.9)/2
        graph.addPlot(pie)

        self.graphView.hostedGraph = graph
    }

    func numberOfRecordsForPlot(plot: CPTPlot!) -> UInt {
        return 4
    }

    func numberForPlot(plot: CPTPlot!, field fieldEnum: UInt, recordIndex idx: UInt) -> NSNumber! {
        return idx+1
    }



}

The error i am getting is from the line : var pie = CPTPieChart() My error is :

Core Plot with swift getting error : "Missing Argument for Parameter ‘frame’ in call"

I am following a tutorial and it is possible that swift has changed, however I am new to the language and can't seem to solve this one. Thanks in advance.

Upvotes: 1

Views: 526

Answers (1)

H. Serdar Çınar
H. Serdar Çınar

Reputation: 1046

I experienced similar problems while developing another app. To my experience, CGRectZero is causing problems with Swift. Try with an actual CGRect or call

var pie = CPTPieChart(frame: CGRectMake(x,y,width,height))

Upvotes: 3

Related Questions