Hi there! I'm currently trying to observe values from firebase RTDB, but every time the values of the children change, the swift app creates a duplicate item with the info, while the value in the app doesn't change.
My functions to observe the values:
var job = JobData()
let _commentsRef = self.ref.child("jobposts")
_commentsRef.observe(.value) { snapshot in
for child in snapshot.children {
print (child)
let snap = child as! DataSnapshot
let dict = snap.value as? [String: AnyObject]
job.id = dict!["id"] as? String ?? "id"
job.title = dict!["title"] as? String ?? "title"
job.company = dict!["company"] as? String ?? "company"
job.city = dict!["city"] as? String ?? "city"
job.salary = dict!["salary"] as? String ?? "salary"
job.creator = dict!["creator"] as? String ?? "creator"
print(job)
print("JOB TITLE: " + job.title!)
self.jobs.append(job)
}
}
}
The view:
ScrollView {
VStack(spacing: 20){
ForEach(session.jobs) { job in
JobCardTemplate(job: job, session: self.session)
}
}
.padding()
}
.navigationBarHidden(true)
.navigationBarTitle(Text("Darbo Pasiūlymai"))
}
Anyone might know why this is happening? Thanks in advance!