Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
834 views
in Technique[技术] by (71.8m points)

swift - How do I check if a firebase database value exists?

I'm using the Realtime Database with Google's Firebase, and I'm trying to check if a child exists.

My database is structured as the following

- / (root)
-   /users/
–-    /james/
--    /jake/
-   /rooms/
--    /room1/
---      (room 1 properties)
--    /room2/
---      (room 2 properties)

I would like to check if room1 exists. I have tried the following:

let roomName:String = "room1"
roomsDB.child(roomName).observeSingleEventOfType(.Value) { 
(snap:FIRDataSnapshot) in
    let roomExists:Bool = snap.value != nil ? "TAKEN" : "NOT TAKEN"
 }

In accessing snap.value it returns a JSON of the properties of that room, but how would I check if the room (/rooms/room1/) is there to begin with?

Comment if any clarification is needed

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...