Latest Realtime Database help for swift

Hi Everyone.
I need some help and guidance for using connecting the Google Firebase Realtime Database on my Swift app. There are some documentation out in the internet although they are outdated and for storyboards. On the other hand, there are documentation’s for swift, but they are complicated. It would be helpful if someone could provide some latest information in a simple manner on how to use realtime database for my swift app. Note that I am not willing to use Cloud Firestore, only realtime database. I am working on an important project and I need a working solution as quick as possible.

Surya

Welcome To the community Surya!

To be clear: you’re looking for up to date Firebase real-time database docs for SwiftUI?

I believe all this info should be accurate

You would put it in a view model or function in your SwiftUI view

But here’s a link for a SwiftUI tutorial

1 Like

Thanks for the info, although I believe so Google Documentation was the one which I was telling outdated. I mostly wanted to know the step by step instructions for the connection between the Realtime Database and Swift. There, I did not know where to place those lines of code. Even if I try to do as they say, a problem shows up.

Your second message was useful, but the application was different. As mentioned before, I wanted a Realtime Database, not Firestore.

As a end message, I need a recent tutorial on how todo this, it is a critical situation for me and it would be much appreciated if someone could help

Cloud Firestore is effectively a real time database but is better. See this documentation regarding comparing Cloud Firestore to Realtime Database.

https://firebase.google.com/docs/database/rtdb-vs-firestore

I am working on a project which uses only real-time database, so it is important that I am sticking to that. I am not only making a swift app, but also a python application. So, I am using real-time database for my project

It would be appreciated if someone could help on real-time database.

Surya

Firebase docs is the best place to look. Much of the code is similar, with SwiftUI it’s different where you put the code

Okay, thank you for your guidance. Anyways, I will definitely be looking at the Firebase docs although I just need a little advice about where I keep the code in. As you mentioned, it is different in swiftui, so could you give a little help on that.

Surya

That depends on what you are trying to do.

What are you trying to do? Just fetch data?

Thanks for reaching out. My application should have the capability to fetch and write data on the real-time database.

I just need to know how todo this and where to keep this because the docs are not for swiftui and only for the storyboard and swift mixtures.

Surya

Swift is the programming language. SwiftUI and Storyboard are just two different ways to build the UI (user interface)

If you want to write data you would put the code behind a button (when it’s tapped). In there that’s where you’d get the values of text fields and use Firebase to actually write the data to the database

To read it you can add code for fetching the data in the onAppear modifier of a view

Thanks, could you give an example, such as how to set it up using swiftui and swift along with where to keep the code. That would be the solution.

To post data to Firebase

Button {
   // Firebase code here
} label: {
Text (“Click here”)
}

In your SwiftUI view inside the .onAppear modifier add the code for fetching from Firebase. Or you can use a viewModel

I know about the button concepts and all although I need to know how you need to set up the module, and where you keep that code. So, it would be beneficial if you could provide an
example swiftui and swift project to show where you keep the code.

That’s where googling and figuring out how to put the pieces together comes from.

FireStore is again very similar, so a lot of concepts from those tutorials apply to the real-time database

Like this: Building a to-do list app with SwiftUI and Firebase (Part 1) - YouTube

But also here’s another after googling: “SwiftUI Firebase realtime database