TimeForColdDrink — Firebase Database + Authentication, FBLogin Demo (Swift)

1. GoogleSheets to Firebase data

It is pretty simple to follow the link to export your data into firebase. Keep in mind that data in firebase will be array type.

2. Install Facebook SDK

There is some issue in Facebook SDK and make sure install your pod with

pod ‘FacebookCore’, ‘~> 0.2’
pod ‘FacebookLogin’, ‘~> 0.2’
pod ‘FacebookShare’, ‘~> 0.2’
pod ‘FBSDKCoreKit’, ‘~> 4.22.1’
pod ‘FBSDKLoginKit’, ‘~> 4.22.1’
pod ‘FBSDKShareKit’, ‘~> 4.22.1’

3. Install Firebase SDK

Official Guides:

Good Tutorial:

4. Firebase Realtime Database

There are 2 ways to read data: observeEvent and observeSingleEvent which is quite different .

ObserveEvent: Once you executed, firebase will send data to your app whenever data is changed. So it is more like a stream of data and when you are loading UI, the data may not be ready to be read and it may cause your UI to be blank.

To solve this we use completion: @escaping

func fetchAllDrinkOrdersUid(completion: @escaping ([String]) -> ()) {var newAllUid = [String]()ref = Database.database().reference()ref.child(“orderList”).observe(.value, with: { (snapshot) innewAllUid = []for uid in snapshot.children {if let uid = uid as? DataSnapshot {DispatchQueue.main.async {newAllUid.append(uid.key)print(newAllUid)completion(newAllUid)}}}})}fetchAllDrinkOrdersUid { (newAllUid) inprint("complete fetch")self.allUid = newAllUidprint(self.allUid)}

ObserveSingleEvent: Firebase send you data when you execute the function. Ideal for UI element that you don’t expect to change.

Github Link:

If you having any compile errors, please fix the error with :

  1. “$0.toUIntMax() as UInt64” should be replaced with UInt64($0)

2.

let substr = String(cleaned)
if substr.characters.count > 10 {
return String(substr.prefix(9))
} else {
return substr
}

to replace this piece:

let range = 0 ..< min(10, cleaned.count)
let characters = cleaned[range].map(Character.init)
return String(characters)

--

--