Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func getAllDevices(userID: String, completionHandler:@escaping (([DeviceRoom])->Void)){
- var homeID: String = ""
- _ = Firestore.firestore().collection("users/4oKS4F0uejdyxEZZ340v/homes" ).limit(to: 1).getDocuments{ (homeSnap,error) in
- if error != nil {
- print(error?.localizedDescription as Any)
- return
- }else {
- for home in (homeSnap?.documents)! {
- homeID = home.documentID
- _ = Firestore.firestore().collection("users/4oKS4F0uejdyxEZZ340v/homes/\(homeID)/rooms").getDocuments(completion: { (roomsSnap, error) in
- if error != nil{
- print(error?.localizedDescription)
- return
- }else{
- for room in (roomsSnap?.documents)! {
- _ = Firestore.firestore().collection("users/4oKS4F0uejdyxEZZ340v/homes/\(homeID)/rooms/\(room.documentID)/devices").getDocuments(completion: { (devicesSnap, error) in
- if error != nil{
- print(error.debugDescription)
- return
- }else{
- for device in (devicesSnap?.documents)! {
- do{
- let device = try DeviceRoom(fromDictionary: device.data())
- self.devices.append(device)
- print(self.devices)
- }catch {
- print("errore")
- }
- }
- }
- })
- }
- }
- completionHandler(self.devices)
- })
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment