Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I do user interface work on the main thread while using Firebase?

I heard that I should always do user interface work on the main thread while reading data from Firebase.

I tried to do self.tableView.reloadData on the background thread inside a Firebase observe(.value) function and the app did not crash or freeze.

databaseReference.observe(.value) { [weak self] snapshot in
        guard let self = self else { return }
        self.tableView.reloadData()
}

I tried to do the same work inside getData function instead of observe(.value) function and the app crashed.

databaseReference.getData { [weak self] error, snapshot in
        guard let self = self else { return }
        self.tableView.reloadData()
}

So why the app crashed inside getData function and it did not crash inside observe(.value) function?

like image 756
Fawzi Rifai Avatar asked May 04 '26 08:05

Fawzi Rifai


1 Answers

firebaser here

While the Firebase SDK performs its network and other I/O on a background thread, it actually calls your callback on the main thread.

But it seems that getData does not do that here, which is a bug. So thanks for catching and reporting that. 🙏

I filed bug #8245 on the Github repo, so check there for progress.

like image 50
Frank van Puffelen Avatar answered May 07 '26 13:05

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!