0

How can I get the value of the post where username = current user and isCompleted = false.

    override func viewWillAppear(animated: Bool) {
    // How can I make a query to get the post along with the current user and the isCompleted = false.
    let postRef = FIRDatabase.database().reference().child("posts").queryOrderedByChild("username").queryEqualToValue(FIRAuth.auth()!.currentUser!.displayName!)
    // If I write the query like below if it will through error
    // let postRef = FIRDatabase.database().reference().child("posts").queryOrderedByChild("username").queryEqualToValue(FIRAuth.auth()!.currentUser!.displayName!).queryOrderedByChild("isCompleted").queryEqualToValue(false)


    postRef.observeEventType(.Value, withBlock: { (snapshot) in



        var newPosts = [TodoItemDatabase]()
        for post in snapshot.children{



            let post = TodoItemDatabase(snapshot: post as! FIRDataSnapshot)
            newPosts.insert(post, atIndex: 0)

        }
        toDoList = newPosts

        dispatch_async(dispatch_get_main_queue(), {
            self.toDoListTable.reloadData()
        })
    }) { (error) in
        print(error.localizedDescription)
    }

}

Below is the data structure for the post

enter image description here

0 Answers0