Making Firebase Realtime Database behave in real-time using the notification/observer pattern

Reactive Firebase Realtime Database Using Swift

Update the frontend as the backend changes in real-time

Kenny Dubroff
DevGauge
Published in
6 min readOct 23, 2021

--

Adding and deleting values from Firebase updates the UI immediately

Are you working with Firebase Realtime Database and wish your UI would just update when the backend does? This can be really helpful when changes can come from anywhere — i.e. in a multi-user app where one user performing an action may change another user’s data. The good news is you can implement such a strategy fairly easily without using a reactive framework such as RxSwift or Combine.

In this article, you’ll learn to use the notification/observer pattern, combined with Firebase’s powerful observe method to implement an actively listening frontend. That means when something changes in the backend, the frontend gets updated quickly. If your internet is blazing fast, it may happen so quickly that it can be hard to distinguish which change occurred first.

Note: You should be familiar with starting a project with Firebase before beginning this tutorial. If you aren’t, check out this Firebase tutorial. Make sure to start your database in test mode to avoid having to authenticate.

Make a database controller

--

--

Kenny Dubroff
DevGauge

I’m a Full Stack iOS Developer with a passion for writing clean, reusable code.