I need this array
self.values.append(value)
in order to append another array with the values from the array above^. Pretty much i need to pass one array to another function with the appended values.
func updateChartValues() -> (LineChartDataSet) {
self.recieveChartValues()
var entries: [ChartDataEntry] = Array()
for i in 0 ..< values.count {
entries.append(ChartDataEntry(x: Double(i), y: Double(values[i]), data: UIImage(named: "icon", in: Bundle(for: self.classForCoder), compatibleWith: nil)))
How can I get these values that are appended from recieveChartValues() to updateChartValues? The main confusion is because they are appended from Firebase.
func recieveChartValues() {
//Firebase Initialization
var ref: FIRDatabaseReference!
ref = FIRDatabase.database().reference()
ref.child("general_room_index").observeSingleEvent(of: .value, with: {(snap) in
print("error3")
if let snaps = snap.value as? [Any]{
for val in snaps {
if let value = val as? Int{
self.values.append(value)
//print(self.values)
}
}
}
})
}//retrive values func
func updateChartValues() -> (LineChartDataSet) {
self.recieveChartValues()
var entries: [ChartDataEntry] = Array()
for i in 0 ..< values.count {
entries.append(ChartDataEntry(x: Double(i), y: Double(values[i]), data: UIImage(named: "icon", in: Bundle(for: self.classForCoder), compatibleWith: nil)))
print("Enetrie ", entries)
}
self.dataSet = LineChartDataSet(values: entries, label: "Bullish vs. Bearish")
self.dataSet.mode = LineChartDataSet.Mode.cubicBezier
return dataSet
}
recieveChartValuesand invoke that closure from the Firebase completion closure