This is a simple Swift class that provides easy methods to query data from your Firebase Database.
This library allows users to treat their default tree structure database in Firebase as a relational database (similar to the usage of Parse).
All that is needed is to create your FIRDatabaseReference then pass it as a parameter into one of our functions to retrieve your desired data.
It includes the following query methods:
- queryById
- queryByStringContains
- queryByListContains
- queryByListContainsSublist
- queryByNotEqualTo
- queryByLessThan
- queryByLessThanOrEqualTo
- queryByGreaterThan
- queryByGreaterThanOrEqualTo
Makre sure you're on the correct repo branch: 'FirebaseUtilsCocoaPod'
Install FirebaseUtils with: CocoaPods
pod'FirebaseUtils'First import Firebase and FirebaseAuth to your selected ViewController.
import Firebase
import FirebaseAuthTo sign into Firebase:
FIRAuth.auth()?.signIn(withEmail:"email@domain.com", password:"password", completion:nil)Create your desired reference where you want to pull the data from:
letref=FIRDatabase.database().reference(withPath:"users")Create a variable to reference our FirebaseUtils:
letfirebaseUtils=FirebaseUtils()Create a block variable in which you determine what you want to do with the resulting object, such as print, return, etc. (in this example, the object is being printed):
letblock={ object ->Voidinprint(object)}Use the firebaseUtils variable and block variable as a parameter to call any one of our functions above (in this example, queryByStringContains is being called):
firebaseUtils.queryByStringContains(fieldName:"image", ref: ref, inputValue:"https://www.example.com", withBlock: block)View our FirebaseUtils.swift file for more specifics on each function, the required parameters, and what results will be returned.
Supports iOS 8 and above. Xcode 7.0 is required to build the latest code written in Swift 3.0.