July 2018 Summaries
1 posts from Firebase
Filter
Month:
Year:
Post Summaries
Back to Blog
Firebase’s asynchronous APIs, such as Firestore’s `getDocuments`, return results later through closures, so code placed immediately after a query often runs before downloaded data is available, leading to empty arrays and prematurely reloaded table views. Moving UI updates into the Firestore callback ensures data is loaded first, but placing all query and update logic in a view controller can create an overly large controller. A cleaner approach is to wrap Firebase calls in separate data-management or downloader classes that expose completion handlers, allowing the view controller to manage presentation concerns such as activity indicators, table reloads, and error alerts. Completion handlers can return either no value when shared state is used or, preferably, an array of downloaded model objects and an optional error, avoiding dependence on singletons and making failures available to the UI. This pattern can also be applied to other Firebase services that use closures, including Realtime Database, Authentication, Cloud Storage, Cloud Functions, and ML Kit.
Jul 02, 2018
1,234 words in the original blog post.