0
    ref = Database.database().reference()

    let currentUserID = Auth.auth().currentUser?.uid

    let userRef = ref.child("users").child(currentUserID!)

    let userRefQuery = userRef.queryOrdered(byChild: "requests").queryEqual(toValue: "received")

    userRefQuery.observeSingleEvent(of: .value, with: { (snapshot) in

        if (snapshot.value is NSNull) {

            print("no data found")
            return
        }

        print("value:")
        print(snapshot.value)

        print("key:")
        print(snapshot.key)

    })

Firebase Database

How can I get the userIDs of users under "requests" which has a value of "received". Because it might also be "sent". Currently, I am not getting any data!

2 Answers2

0

This is how I got it worked:

ref = Database.database().reference()

let currentUserID = Auth.auth().currentUser?.uid

refHandle = ref.child("users").child(currentUserID!).observe(.value, with: { (snapshot) in

    print(snapshot)

    if let userDict = snapshot.value as? [String: Any] {

        if let requests = userDict["requests"] as? [String: String] {

            print(requests)

            for request in requests {

                if request.value == "sent" {

                    self.userIDs.append(request.key)
                    print(request.key)

                }

            }

        }


    }

}
0

For the question that you deleted, instead of:

char temp = s[start]

do

char temp = s[i];

boop_the_snoot
  • 3,209
  • 4
  • 33
  • 44
Ryne
  • 1,195
  • 2
  • 14
  • 32
  • Yes, but that would skip all whitespaces. And I don't want that. I just want to skip the whitespace at the starting of a new line. Anyways, thanks a lot – Kinshuk Singh Oct 04 '17 at 04:40
  • char temp = s[i] + ' '; will add whitespace. if you also remove the cout << "\n" line it will put your string in one line and there will be whitespaces between the words. if your looking to get something different and still need help feel free to let me know what results your trying to get – Ryne Oct 04 '17 at 05:01
  • I was looking for something different but not got it. Thank a lot anyways! – Kinshuk Singh Oct 04 '17 at 12:59