Getting error while appending arrays in snapshot. I want to retrieve all values from these arrays EngNames , UrNames and cakeImages in the snapshot so the values can appear on table view cells.
However I can retrieve all values of Cake Rate Label and Eng Name Label from Firebse but i want just retrieve all the cakeRatelabel values of rate from firebase and rest of the data that is EngNames , UrNames and cakeImages i want to retrieve localy from defined arrays and images in assets respectively.
help me to accomplish this, any help will be highly appreciated.
View Controller
TestTabelViewController
import UIKit
import Firebase
class TestTableViewController: UITableViewController {
@IBOutlet var cakeTableView: UITableView!
var ref = FIRDatabase.database().reference()
struct Cake {
let cakeEngNames: String
let cakeUrNames: String
let cakeImages: UIImage
var cakeRates: String
}
var cakes = [Cake]()
var cakeImages = [UIImage(named : "bakery_almond_cake")!,UIImage(named : "bakery_azna_mental_cake")!, UIImage(named : "bakery_black_forest_cake")!, UIImage(named : "bakery_checker_cake")!, UIImage(named : "bakery_cheese_cake")!, UIImage(named : "bakery_chocolate_cake")!, UIImage(named : "bakery_coconut_macaroni_cake")!, UIImage(named : "bakery_cream_cake")!, UIImage(named : "bakery_cream_layer_cake")!, UIImage(named : "bakery_fruit_cake")!, UIImage(named : "bakery_lemon_layer_cake")!, UIImage(named : "bakery_pineapple_cake")!, UIImage(named : "bakery_plain_cake")!,UIImage(named : "bakery_pulm_cake_almond")!,UIImage(named : "bakery_rich_plum_cake")!,UIImage(named : "bakery_swiss_cake")!]
var EngNames = ["Almond Cake", "Azna cake", "Black forest Cake","checker cake", "cheese cake", "chocolate cake","coconut cake", "cream cake", "cream layer cake", "fruit cake", "lemon cake", "pine apple cake", "plain cake", "plum cake", "rich cake", "swiss cake"]
var UrNames = ["Almond Badam cake", "Azna wala cake", "Black kala forest Cake","checker wala cake", "cheese wala cake", "chocolate wala cake","coconut wala cake", "cream wala cake", "cream wala layer cake", "fruit wala cake", "lemon wala cake", "pine apple wala cake", "plain wala cake", "plum wala cake", "rich wala cake", "swiss wala cake"]
override func viewDidLoad() {
super.viewDidLoad()
let almondSnap = ref.child("Hyderabad").child("Bakery").child("Cake")
almondSnap.observe( .value, with: { (snapshot) in
if snapshot.hasChildren(){
for snap in snapshot.children {
if let node = snap as? FIRDataSnapshot , let rate = node.value as? Int {
self.cakes.append(Cake(cakeEngNames: EngNames,
cakeUrNames: UrNames,
cakeImages: cakeImages,
cakeRates: String(rate)))
}
}
self.cakeTableView.reloadData()
}
})
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.cakes.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell", for: indexPath) as! TestTableViewCell
cell.cakeImage.image = self.cakes[indexPath.row].cakeImages
cell.cakeEngLabs.text = self.cakes[indexPath.row].cakeEngNames
cell.cakeUrLabs.text = self.cakes[indexPath.row].cakeUrNames
cell.cakeRateLabs.text = self.cakes[indexPath.row].cakeRates
return cell
}
}


Caketakes a String and you are attempting to pass an array of String; you need to find the appropriate index and use that with the arrays. How do you know which cake the firebase record applies to?