首页 > 解决方案 > Swift firebase .observe or .observeSingleEvent won't work

问题描述

I've got a problem with my firebase .observe and .observeSingleEvent.

    ref = Database.database().reference()
    let postRef = ref.child("posts").child("post")
    print(postRef)

    postRef.observeSingleEvent(of: .value) { (snapshot) in

        if let postDict = snapshot.value as? [String : AnyObject] {
            print(postDict)
        }
    }

I do this in my viewDidLoad(). the 'print(postRef)' prints the right path to my firebase.

https://-----.firebaseio.com/posts/post

After that I get nothing returned.

child structure: child structure

Why won't it print the "postDict"?

Now I see this in my project: CFNetwork/Foundation/Security.framework turns red!

标签: iosswiftfirebasefirebase-realtime-database

解决方案


When I re-added the missing frameworks ->

project -> build phases -> Link Binary Libraries

It worked again! Thanks for the help, though!


推荐阅读