FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. The avoidance of hard coded dependencies
FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. PERSISTENCE The avoidance of hard coded dependencies
FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. PERSISTENCE FIREBASE The avoidance of hard coded dependencies
FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. PERSISTENCE NETWORKING ALAMOFIRE FIREBASE The avoidance of hard coded dependencies
FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. PERSISTENCE NETWORKING ALAMOFIRE ANALYTICS FIREBASE The avoidance of hard coded dependencies
FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. PERSISTENCE NETWORKING ALAMOFIRE ANALYTICS FIREBASE The avoidance of hard coded dependencies
FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. PERSISTENCE NETWORKING STUB ANALYTICS FIREBASE The avoidance of hard coded dependencies
FIREBASE ARCHITECTURE If you are adding 3rd party services, keep them isolated from your app as much as possible. And they can be easily removed for unit testing. PERSISTENCE NETWORKING STUB ANALYTICS STUB STUB The avoidance of hard coded dependencies
FIREBASE ▸ Store ▸ Lies between your model and persistence layers ▸ Converts between raw persistence data and your model, and vice versa ARCHITECTURE VIEW CONTROLLER MODEL PERSISTENCE
FIREBASE ▸ MVC-RS ▸ Greg Lhotellier (@greg3z) ▸ https://medium.com/swift-programming/mvc- rs-8780e73e9ff4 ▸ R - Router, similar to Coordinator or VIPER ▸ S- Store ▸ Can be used with MVVM ARCHITECTURE
FIREBASE ▸ A good/simple architecture ▸ But can be improved ▸ Data may be created at one location and consumed elsewhere. ▸ From: network, BLE, user interaction, database ▸ To: database, UI STORE
FIREBASE ▸ A good/simple architecture ▸ But can be improved ▸ Data may be created at one location and consumed elsewhere. ▸ Read-only source ▸ Write-only sink STORE
FIREBASE ▸ A good/simple architecture ▸ But can be improved ▸ Data may be created at one location and consumed elsewhere. ▸ Read-only source ▸ Write-only sink - or sinks STORE
FIREBASE protocol Source { var onData: ((Int) -> Void) { get set } } protocol Sink { var writeData: ((Int) -> Void) { get } } protocol Store { init(source: Source, sinks: [Sink]) } STORE
FIREBASE ▸ Firebase comes with a default authentication view controller ▸ Can be configured for multiple authentication providers ▸ Customisable via UIAppearance and other tricks, but not directly LOGIN
FIREBASE ▸ Firebase comes with a default authentication view controller ▸ Can be configured for multiple authentication providers ▸ Customisable via UIAppearance and other tricks, but not directly ▸ Text, colours and icons are pre- set LOGIN
FIREBASE ▸ Button drop shadow is not configurable ▸ Buttons do not use dynamic type ▸ You need to register your app with Facebook ▸ You can make your own, but it’ll take time. LOGIN
FIREBASE ▸ Login status can change ▸ Tokens can expire, but they are automatically refreshed ▸ The logged in user is `FIRAuth.auth()?.currentUser` LOGIN
FIREBASE ▸ Login status can change ▸ Tokens can expire, but they are automatically refreshed ▸ The logged in user is `FIRAuth.auth()?.currentUser` ▸ But don’t trust it, it’s cached. LOGIN
FIREBASE ▸ Login status can change ▸ Tokens can expire, but they are automatically refreshed ▸ The logged in user is `FIRAuth.auth()?.currentUser` ▸ But don’t trust it, it’s cached. ▸ Better to observe authentication state LOGIN
FIREBASE ▸ addStateDidChangeListener ▸ In class FIRAuth ▸ Called back immediately. And then after every state change, including token refresh ▸ So mostly can be ignored. ▸ But it will notify you of any enforced logouts. LOGIN
FIREBASE ▸ FIRDatabase ▸ Entry point for accessing the data ▸ Not the database data itself ▸ Controls online/offline mode ▸ Persistence, persistence cache size DATABASE
FIREBASE ▸ FIRDatabase ▸ Entry point for accessing the data ▸ Not the database data itself ▸ Controls online/offline mode ▸ Persistence, persistence cache size ▸ Callback queue DATABASE
FIREBASE ▸ FIRDatabase ▸ Entry point for accessing the data ▸ Not the database data itself ▸ Controls online/offline mode ▸ Persistence, persistence cache size ▸ Callback queue (main thread by default) DATABASE
FIREBASE ▸ Represents a node in the database ▸ Read, write & remove data to/from the node ▸ Provides a lot of APIs with completion handlers in the case of errors DATABASE REFERENCE
FIREBASE ▸ Represents a node in the database ▸ Read, write & remove data to/from the node ▸ Provides a lot of APIs with completion handlers in the case of errors ▸ Can specify priority for nodes to provide custom ordering of children DATABASE REFERENCE
FIREBASE ▸ Represents a node in the database ▸ Read data by async observations ▸ Large number of observing options, 8 different APIs DATABASE REFERENCE
FIREBASE ▸ Represents a node in the database ▸ Read data by async observations ▸ Large number of observing options, 8 different APIs ▸ Observe once, or on modification, on new children, on removal, on move or on any change DATABASE REFERENCE
FIREBASE ▸ Represents a node in the database ▸ Read data by async observations ▸ Large number of observing options, 8 different APIs ▸ Observe once, or on modification, on new children, on removal, on move or on any change. ▸ Limit returns to get progressive downloads DATABASE REFERENCE
FIREBASE ▸ Small example - so MVC ▸ Using Store-based architecture ▸ Generate data to write out to Firebase ▸ Observe updates in Firebase and display them LIVE CODING
FIREBASE ▸ Small example - so MVC ▸ Using Store-based architecture ▸ Generate data to write out to Firebase ▸ Observe updates in Firebase and display them ▸ Requires login LIVE CODING