Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 2 (Xcode 7) Bad address on accessing chart view #563

Closed
arinhouck opened this issue Nov 22, 2015 · 2 comments
Closed

Swift 2 (Xcode 7) Bad address on accessing chart view #563

arinhouck opened this issue Nov 22, 2015 · 2 comments

Comments

@arinhouck
Copy link

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=2, address=0x1a1f14400).
The process has been returned to the state before expression evaluation.

pieChartView is defined according to debugger

(lldb) po pieChartView
<UIView: 0x15820de90; frame = (0 0; 375 667); autoresize = W+H; tintColor = UIDeviceRGBColorSpace 0 0.65098 0.352941 1; layer = <CALayer: 0x1582037d0>>

Controller

//
//  PieChartViewController.swift
//  gradebuildr
//
//  Created by Arin Houck on 11/21/15.
//  Copyright © 2015 Gradebuildr. All rights reserved.
//

import UIKit
import Charts

class PieChartViewController: UIViewController {

    var weights: [String]!

    @IBOutlet weak var pieChartView: PieChartView!

    override func viewDidLoad() {
        super.viewDidLoad()
        weights = ["Assignments", "Homework", "Exam"]
        let percentages = [25.0, 50.0, 25.0]
        setChart(weights, values: percentages)

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    func setChart(dataPoints: [String], values: [Double]) {
        pieChartView.noDataText = "You need to provide data for the chart."
        pieChartView.centerText = "20%"
        pieChartView.centerTextColor = UIColor.whiteColor()
        pieChartView.descriptionText = ""
        pieChartView.animate(xAxisDuration: 1.5)
        pieChartView.legend.enabled = false
        pieChartView.userInteractionEnabled = false
        pieChartView.backgroundColor = UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0)
        pieChartView.holeColor = UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0)

        var dataEntries: [ChartDataEntry] = []

        for i in 0..<dataPoints.count {
            let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
            dataEntries.append(dataEntry)
        }

        let pieChartDataSet = PieChartDataSet(yVals: dataEntries, label: "%")
        let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
        pieChartView.data = pieChartData
        pieChartView.data?.setValueTextColor(UIColor.clearColor())

        let colors = [UIColor.blackColor(), UIColor(red: 251/255.0, green: 38/255.0, blue: 108/255.0, alpha: 1.0)]
        pieChartDataSet.colors = colors
    }

}

Crashes on this line: pieChartView.noDataText = "You need to provide data for the chart."
However it just crashes on any method or variable accessed through the PieChartView.

@pmairoldi
Copy link
Collaborator

Your IBOutlet is probably not set.

@arinhouck
Copy link
Author

Still learning the ropes of Swift. Turned out, I was forcing the PieChartView on the outlet however I did not actually change the UIView class to PieChartView and the module to Charts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants