instant-solutions / ISTimeline

Simple timeline view written in Swift 3
Apache License 2.0
1.01k stars 79 forks source link

Add Objects From Array #10

Closed DevCSI closed 7 years ago

DevCSI commented 7 years ago

How to Add Objects from Array I tried this but it only adding last Object

let dataArr = ["2011","2012","2013","2014","2015"]

    for str in dataArr
    {
        print(str)

        let myPoin = [
            ISPoint(title: str, description: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam.", pointColor: black, lineColor: black, touchUpInside: touchAction, fill: false)]
        timeline.points = myPoin
    }
holzleitner commented 7 years ago

Hi! You are assigning the array "myPoin" every iteration. So only the last point is included in the array.

As mentioned in the README.md, you can either set the whole array or append individual points. Have a look: Add points to the timeline

Try something like:

let data = ["2011", "2012", "2013", "2014", "2015"]

data.forEach { str in
    let point = ISPoint(title: str)
    timeline.points.append(point)
}