Supratik Majumdar Supratik Majumdar - 5 months ago 49
Swift Question

TKChartDataPoint does not conform to expected type Sequence

I am starting out with Telerik and tried to do the demo project provided.

As I am trying to declare a TKChartDataPoint it gives out an error:
Error Image

Code Snippet:

class ViewController: UIViewController {

let x = 10
let y = 10

override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.

let chart = TKChart(frame: self.view.bounds.insetBy(dx: 15, dy: 15))
chart.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]

var randomNumericData = [TKChartDataPoint]()
for i in 0..<10 {

//Error Here
randomNumericData += TKChartDataPoint(x: i, y: Double(arc4random() % 100))


chart.addSeries(TKChartLineSeries(items: randomNumericData))

chart.title.isHidden = false
chart.title.text = "This is a chart demo"
chart.legend.isHidden = false

chart.allowAnimations = true


You should just use append to add your object to the array:

randomNumericData.append(TKChartDataPoint(x: i, y: Double(arc4random() % 100)))

You can use += if you really want, but randomNumericData is an Array so to add to it with + or +=, the added part should also be an array:

randomNumericData += [TKChartDataPoint(x: i, y: Double(arc4random() % 100))]

In my opinion, the first solution is preferred.