Fred van Rijswijk
Fred van Rijswijk

Reputation: 588

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'

Upvotes: 3

Views: 4477

Answers (2)

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

Upvotes: 1

Chris
Chris

Reputation: 8020

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

Upvotes: 8

Related Questions