To check for missing data (snapshot == NULL), he did this
let refToCheck = myRootRef.childByAppendingPath(channelNameString)
refToCheck.observeEventType(.Value, withBlock: { snapshot in
if snapshot.value is NSNull {
print("snapshot was NULL")
} else {
print(snapshot)
}
})
The queries are pretty heavy compared to .observeEventType, and since you already know which specific path you will check, it will work much better.
Edit: you can also use
if snapshot.exists() { ... }
Firebase , , .
Firebase 3.x Swift 3.x
let refToCheck = myRootRef.child(channelNameString)
refToCheck.observe(.value, with: { snapshot in
if snapshot.exists() {
print("found the node")
} else {
print("node doesn't exist")
}
})
1) , .exists .
2) Firebase, , node , .
node , node, :
let refToCheck = myRootRef.child(channelNameString)
refToCheck.observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("found the node")
} else {
print("node doesn't exist")
}
})