3

I was trouble in 2 weeks, so please let me ask question.

Situation

XCode 7.2 Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81) https://github.com/yosuke1985/ios-charts

iOS Chart ttps://github.com/danielgindi/ios-charts

This code is from

ttp://www.appcoda.com/ios-charts-api-tutorial/

What I want

I want to use this framework, but error is EXEC_BAC_ACCESS,

I only put the window object on Viewcontroller by StoryBoard, and connect as BarChartView Class.

And wanna show Bar Chart, When I change the attribute, "noDataText" and "noDataTextDescription" It doesnt work, and cannot figure out the error comes from.

    barChartView.noDataText = "there is no data"
    barChartView.noDataTextDescription = "give me the reason"

Only these code doesn't work so, I start to think the problem is comes from version of Swift or XCode? Please give me advice to solve this problem.

error

EXEC_BAC_ACCESS ERROR, Screen Shot

import UIKit
import Charts

class ViewController: UIViewController {
var months: [String]!


@IBOutlet weak var barChartView: BarChartView!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    barChartView.noDataText = "there is no data"
    barChartView.noDataTextDescription = "give me the reason"
    self.months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]

    setChart(months, values: unitsSold)
}


func setChart(dataPoints: [String], values: [Double]) {
    barChartView.noDataText = "You need to provide data for the chart."


    var dataEntries: [BarChartDataEntry] = []

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

    let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
    let chartData = BarChartData(xVals: months, dataSet: chartDataSet)
    barChartView.data = chartData
}


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


}
YOSUKE
  • 331
  • 3
  • 13
  • continue running your app and post the error message + stack trace here. – luk2302 Jan 08 '16 at 08:46
  • thank you for comment, this is the error http://i.stack.imgur.com/TwlfT.png – YOSUKE Jan 08 '16 at 08:48
  • That is the assembler code, nobody is going to be able to help you looking at that. – luk2302 Jan 08 '16 at 08:48
  • thanks, error is only said "(lldb) " and I check breakpoint like this http://stackoverflow.com/questions/7960816/xcode-stack-trace-not-appearing-in-console but doesnt show the error by breakpoints. – YOSUKE Jan 08 '16 at 08:54
  • When xcode stops and debug window is on the left (the stack trace) (your image) can you click on the ViewController.viewDidLoad and send the screenshot again please. – oyalhi Jan 08 '16 at 09:01
  • http://i.stack.imgur.com/gNvaV.png This is the error , I uploaded again. thanks. – YOSUKE Jan 08 '16 at 09:06

1 Answers1

5

Solved. You need to set the Class of bar chart view to let the storyboard know which class to initialize. Custom class is empty now, which means it will be initialized as UIView and be use as BarChartView. See https://i.stack.imgur.com/uefli.png

John Wong
  • 342
  • 2
  • 10
  • Thank you so much Mr John and, Im very embarrassed to ask like this basic mistake... You are my hero – YOSUKE Jan 08 '16 at 09:19