Latest 1.0.0
License MIT
Platforms ios 8.0
Dependencies Firebase/Database
Authors ,


FirebaseHelper is a small wrapper over Firebase’s realtime database, providing streamlined methods for get, set, delete, and increment values.


  • [x] Setup Firebase Realtime Database Ref
  • [x] Read values (get)
  • [x] Write/Update values (set)
  • [x] Remove values (delete)
  • [x] Increment values (increment)


Swift 4


FirebaseHelper is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'FirebaseHelper'


Initialize an instance of FirebaseHelper:

import Firebase
import FirebaseHelper

let firebaseHelper = FirebaseHelper(FirebaseDatabase.Database.database().reference())

FirebaseHelper(_ ref: DatabaseReference) takes in a DatabaseReference. Generally you’d want this to be the root of your database.

For convenience, you can add something like this to your project:

extension FirebaseHelper {
    static let main: FirebaseHelper = {

And now you can simply call FirebaseHelper.main to access this instance of FirebaseHelper from anywhere in your project.

Common Database Operations



FirebaseHelper.main.get("users", "john123", "favoriteFood") { result in
    switch result {
      case .failure(let error):
        // handle error
      case .success(let data):
        // get string from data


public func get(_ first: String, _ rest: String..., completion: @escaping (Result<DataSnapshot, Error>) -> Void)

get() takes in a variadic parameter of child nodes that will be built on the DatabaseReference you initialized your instance of FirebaseHelper on.

The callback returns a Result:

public enum Result<T, Error> {
    case success(T)
    case failure(Error)

In this case, T is DataSnapshot. An error case will either be because an invalid child was passed in or some other error in your database.

Set, Delete, Increment

set(), delete(), and increment() work similarly, but instead of returning a Result, they simply return an Error if one occurred, or nil otherwise.


// The first parameter is an `Any` that gets set at the specified path.
FirebaseHelper.main.set("pizza", at: "users", "john123", "favoriteFood") { error in
    if let error = error {
      // handle error

FirebaseHelper.main.delete("users", "john123", "favoriteFood") { error in
    if let error = error {
      // handle error

FirebaseHelper.main.increment(by: 5, "users", "john123", "favoriteFoodEatenThisMonth") {
    if let error = error {
      // handle error


public func set(_ value: Any, at first: String, _ rest: String..., completion: @escaping (Error?) -> Void)

public func delete(_ first: String, _ rest: String..., completion: @escaping (Error?) -> Void)

public func increment(by amount: Int, at first: String, _ rest: String..., completion: @escaping (Error?) -> Void)

Note: You should only set() accepted value types. See Firebase docs.

Safely Make A DatabaseReference

You will often need to call more complex FirebaseDatabase functions, such as building a query and calling observe(_ eventType: with block:) on it. FirebaseHelper can still help with that:

let ref = try? FirebaseHelper.main.makeReference("users", "john123", "eatingHistory")
let handle = ref?.queryOrdered(byChild: "timestamp").queryLimited(toLast: 50).observe(.value) { data in
    // handle data


public func makeReference(_ first: String, _ rest: String...) throws -> DatabaseReference

makeReference will throw an error if passed an invalid child.



FirebaseHelper is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "FirebaseHelper",
    "version": "1.0.0",
    "summary": "Safe and easy wrappers for common Firebase Database functions.",
    "description": "Safe and easy wrappers for common Firebase Database functions like get, set, delete, and increment. Also for creating a DatabaseReference with specified children added to its path. Filters the children and throws an error if a child key is invalid, such as a blank or double slashes. Without this check, Firebase Database crashes at runtime.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "quanvo87": "[email protected]",
        "Wilson Ding": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.0.0"
    "platforms": {
        "ios": "8.0"
    "swift_version": "4.0.3",
    "source_files": "FirebaseHelper/Classes/**/*",
    "static_framework": true,
    "dependencies": {
        "Firebase/Database": [
            "~> 4.1"

Pin It on Pinterest

Share This