Firebase + Swift. How to delete data.

David Seek
Swift2Go
Published in
3 min readAug 28, 2018

--

Find more useful articles at www.davidseek.com

As one of the “early days” users of Firebase, I have recommended implementing it to all my client’s projects. I love the convenience and I love how powerful Firebase is.

In this story I will explain how to delete data from Firebase using Swift.

Let’s assume we have build a social media App with a model called Post. It’s a very common model used in every social media product.

An easy example could be:

struct Post {   let userID: String
let postID: String
let caption: String
let imageURL: String
}

This post model contains the userID of the user who has posted it, the caption (and optional text) and an imageURL, for example. It would be very common to store further meta data like the name of the user who has posted it, maybe the link to the avatar, the date stamp, the location, etc.

Yet the most important part is the postID. The postID is what we will use to store and to delete the post.

It is incredible important to remember that we need the postID, much like our userID, to be 100% unique. 2 posts with the same ID would overwrite each other and cause endless problems.

--

--