Firebase gives me Use of undeclared type with FIRDatabase and FIRDataSnapshot


Firebase IO example Zero to App gives me errors I can't define

// Firebase services
var database: FIRDatabase!

and on

// Create a chat message from a FIRDataSnapshot
func chatMessageFromSnapshot(snapshot: FIRDataSnapshot) -> ChatMessage? {
    let data = snapshot.value as! Dictionary<String, String>
    guard let name = data["name"] as String! else { return nil }
    guard let message = data["message"] as String! else { return nil }
    let chatMessage = ChatMessage(name: name, message: message, image: nil)
    return chatMessage

I'm new to Firebase and want to learn, but the examples gives me errors each time a try or somthing is missing in the documentation...

FIRDatabase and FIRDataSnapshot are giving error: Use of undeclared type 'FIRDataSnapshot' and Use of undeclared type 'FIRDatabase'

Try only importing the frameworks that you need, and not the generic firebase. So if your import looks like this:

import Firebase
import FirebaseStorage
import FirebaseAnalytics
import FirebaseDatabase

try with just

import FirebaseStorage
import FirebaseAnalytics
import FirebaseDatabase
By : Chris

Firebase has crappy documentation and API, as it is true for almost every Google product. Check if retrieved FIRDataSnapshot snapshot has value of [NSNull null] object, not a ‘nil’ as it is stated in their mistaken documentation

This video can help you solving your question :)
By: admin