4

I know this question has been ask several times but none of the solutions work for me. here is my snap shot

Snap (CaseExtend) {
    NYxdSlq8yOgQd3phssRlD =     {
        CaseMinute =         {
            WMKuImjuH0qPIGJhHHJKv =             {
                caseMinute = "";
                dateTime = "Dec 1, 2021 12:20 PM";
                minuteId = WMKuImjuH0qPIGJhHHJKv;
                userId = OtRFaqilTigWvEkUCASvCoEegny1;
            };
        };
        CaseParticipant =         {
            3f7nqmcWFTenePkEB9KoMHLzVtk2 =             {
                userId = 3f7nqmcWFTenePkEB9KoMHLzVtk2;
            };
            OtRFaqilTigWvEkUCASvCoEegny1 =             {
                userId = OtRFaqilTigWvEkUCASvCoEegny1;
            };
        };
        caseId = Oj7TwzDC3HQMJKyTb8Ebi;
        caseNumber = TEST;
        court = "Labour Tribunal";
        courtRoomNo = "";
        date = "2021-12-01";
        extendId = NYxdSlq8yOgQd3phssRlD;
        extendStatus = "Not Extend";
        location = "";
        participantCount = 2;
        profilePicture = "https://firebasestorage.googleapis.com/v0/b/lege-155e1.appspot.com/o/Profile%20Pictures%2FOtRFaqilTigWvEkUCASvCoEegny1.jpg?alt=media&token=676226fa-638b-4175-a8d5-247095f6b86a";
        step = TBM;
        time = "";
        userId = OtRFaqilTigWvEkUCASvCoEegny1;
    };
}

and i retrieve the snapshot using following code,

   ref.child("CaseExtend").queryOrdered(byChild: "userId").queryEqual(toValue: "OtRFaqilTigWvEkUCASvCoEegny1" ).observe(.value, with: { (DataSnapshot) in
            
            
        })

i want to add the caseID, caseNumber, date.. and other values for different variables. is there anyway i can do this?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Do you mean that you want to fetch those values from firebase and assign them to new variables in your app? – Amr Dec 15 '21 at 11:42
  • yes, that's what i want. – Samith Wijesinghe Dec 15 '21 at 11:54
  • you can create a struct in your app with the variables that you want, and after retrieving from firebase you can pass the dictionary [String: Any] to that struct and you get get back what you want. – Amr Dec 15 '21 at 12:02

1 Answers1

0

first of all you are getting all data in casetExtend node all the variables you want to assign is not under that node. for that you need to navigate one level of child node.

ref.child("CaseExtend").queryOrdered(byChild: "userId").queryEqual(toValue: "OtRFaqilTigWvEkUCASvCoEegny1" ).observe(.value, with: { (snapshot) in
            for caseSnapshot in snapshot.children.allObjects as! [DataSnapshot] {

let dict = caseSnapshot.value as? [String: AnyObject] // assign the snapshot to a dictionary
let court = dict!["court"] as? String  ?? "unknown"; // assign the variable

      }
        })