a singleton class to assist interfacing with the database, Firebase storage bucket, caching files, managing your Auth info and interacting with other Auth users
create a personal account / login, logs you into your profile page where you can edit your profile details, upload picture. Everyone has a profile, that's it. Foundation for social media-type apps.
Browse the entire database in a simple UITableView. Firebase sometimes delivers JSON objects as an Array
or Dictionary
, this handles each case, and includes object type detection.
- Install Cocoa Pods:
- in command line navigate to the directory with the .xcodeproj file, type
pod install
- from now on, open the .xcworkspace file
- in command line navigate to the directory with the .xcodeproj file, type
- Copy in your
GoogleService-Info.plist
with your Firebase account info. Get it here:
see Firebase Getting Started Documentation sections Add Firebase to your app and Add the SDK
- Database
- User
- Storage
getData()
get data from databasesetData()
overwrite data at a certain location in the databaseaddData()
generate a new key and add data as a childdoesDataExist()
check if data exists at a certain location
Firebase sometimes stores data as Arrays, but an auto-generated firebase key won't check to match the array type:
using this function checks against the database before adding:
func addData(_ object:Any, asChildAt path:String, completionHandler: ...){}
Corrected:
Firebase comes with FireAuth with a "user" class, but you can't edit it. Solution: create a "users" entry in database with copies of User data but with more info.
- each user is stored under their user.uid
- can add as many fields as you want (nickname, photo, etc..)
all the references to "user" are to our database's user entries, not the proper FIRAuth entry
getCurrentUser()
get all your profile informationgetUser()
get a different user's infoupdateCurrentUserWith()
update your profile with new informationnewUser()
create a new entry for a user (usually for yourself after 1st login)userExists()
check if a user exists
since Firebase Storage doesn't keep track of the files you upload, this maintains a record of the uploaded files in your database
fileCache:[String:Data]
the cache for all incoming files (images/pdfs) from the storage bucketimageFromStorageBucket()
get an image from Firebase storage (or the cache if it's already there)uploadFileAndMakeRecord()
upload a file to storage, make a record in our database, a