Last active
February 5, 2021 21:08
-
-
Save mitnick78/c210501566314f780019d4a6ec79847a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ExoModelFirebase.swift | |
// | |
import Foundation | |
import FirebaseDatabase | |
class ExoModelFirebase: ObservableObject { | |
var ref = Database.database().reference() | |
@Published var exos: [ExoModel] = [] { | |
willSet { | |
objectWillChange.send() | |
} | |
} | |
var section: String = "" | |
func getResultSearch(_ section: String){ | |
DispatchQueue.main.async { | |
self.ref.child("Exercises").queryOrdered(byChild: "pcategory").queryStarting(atValue: section).queryEnding(atValue: section+"\u{f8ff}").observeSingleEvent(of: .value) { (snapshot) in | |
self.exos.removeAll() | |
for exo in snapshot.children { | |
let exoSnapshot = exo as! DataSnapshot | |
print(exoSnapshot) | |
let exoArrayData = exoSnapshot.value as? [String:AnyObject] | |
self.exos.append(ExoModel(pcategory: exoArrayData?["pcategory"] as! String, pdate: exoArrayData?["pdate"] as! String, pheading: exoArrayData?["pheading"] as! String, piconlink: exoArrayData?["piconlink"] as! String, preadcolor: exoArrayData?["preadcolor"] as! String, psimpleblack: exoArrayData?["psimpleblack"] as! String)) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment