SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Downloaden Sie, um offline zu lesen
Rapid Application Development 

with SwiftUI and Firebase
Peter Friese, Developer Advocate, Google
@peterfriese
🔥
Demo 1

Kaffeinated - A coffee tracking app
SwiftUI
• A declarative way to build your UI

• Everything is a view

• Every SwiftUI view is a struct

• You build UIs by composing views
• Views are a function of their state
Better state management!
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
SwiftUI Views
Demo 2
Building a List From Scratch
Improve app quality
Crashlytics
Performance
Monitoring
Test Lab
App Distribution
Grow your app
Analytics
Predictions
Cloud
Messaging
Remote
Config
A/B Testing
Dynamic

Links
In-app
Messaging
Build better apps
Auth
Cloud
Functions
Cloud
Firestore
Hosting
ML Kit
Realtime

Database
Cloud
Storage
bit.ly/what-is-firebase
Mobile Databases - The Hard Way
Database MongoDB, Postgres, MySQL, etc
API Server REST API on top of database
Auth Service Protects the API server
Sync Logic REST API calls, caches, etc
SQLite Store data offline
Cross-platform?
You're going to have to write the
same code multiple times!
App DatabaseServer
One-Time FetchesOffline ModeEffortless Syncing
Document
bird_type:
airspeed:
coconut_capacity:
isNative:
icon:
vector:
distances_traveled:
"swallow"
42.733
0.62
false
<binary data>
{x: 36.4255,
y: 25.1442,
z: 18.8816
[42, 39, 12,
42]
Collection
collection("restaurants").
where("city", " ==", "Cairo").
orderBy(“rating”, "desc").limit(10)
Here ya go!
Add Firebase to Your iOS Project
1. Create a new Firebase project

2. Register your iOS app

3. Download configuration file

4. Install the Firebase Cocoapod

5. Call FirebaseApp.configure()
Kaffeinated Data Model
Fetching Data from Firestore
db.collection("coffees").addSnapshotListener { (querySnapshot, error) in
var coffees = [Coffee]()
querySnapshot ?.documents.forEach { document in
let coffeeName = document.data()["name"] as? String ?? ""
let shortDescription = document.data()["shortDescription"] as? String ?? ""
let description = document.data()["description"] as? String ?? ""
let caffeineAmount = document.data()["caffeineAmount"] as? Int ?? 0
let coffee = Coffee(name: coffeeName,
shortDescription: shortDescription,
description: description,
caffeineAmount: caffeineAmount)
coffees.append(coffee)
}
self.coffees = coffees
}
Fetching Data from Firestore
Firestore & Codable
• One of our most-requested and
longest-running feature requests

• Released on October 22nd, 2019

• Makes fetching and writing much
easier
db.collection("coffees").addSnapshotListener { (querySnapshot, error) in
var coffees = [Coffee]()
querySnapshot ?.documents.forEach { document in
let coffeeName = document.data()["name"] as? String ?? ""
let shortDescription = document.data()["shortDescription"] as? String ?? ""
let description = document.data()["description"] as? String ?? ""
let caffeineAmount = document.data()["caffeineAmount"] as? Int ?? 0
let coffee = Coffee(name: coffeeName,
shortDescription: shortDescription,
description: description,
caffeineAmount: caffeineAmount)
coffees.append(coffee)
}
self.coffees = coffees
}
Fetching Data - w/o Codable
// Model
struct Coffee: Codable, Identifiable {
@DocumentID var id: String?
var name: String
var shortDescription: String
var description: String
}
// Elsewhere, fetch our data:
db.collection("coffees").addSnapshotListener { (querySnapshot, error) in
if let querySnapshot = querySnapshot {
self.coffees = querySnapshot.documents.compactMap { document -> Coffee? in
try? document.data(as: Coffee.self)
}
}
}
Fetching Data - w/ Codable
Saving Data to Firestore
let db = Firestore.firestore()
do {
_ = try db.collection(“users/(user.uid)/consumption/")
.addDocument(from: consumption)
}
catch {
print(“Error: (error.localizedDescription).")
}
Saving Data to Firestore
let db = Firestore.firestore()
do {
_ = try db.collection(“users/(user.uid)/consumption/")
.addDocument(from: consumption)
}
catch {
print(“Error: (error.localizedDescription).")
}
Saving Data to Firestore
We didn’t sign in, so what’s
this kind of magic?
Anonymous Auth
Auth.auth().signInAnonymously() { (authResult, error) in
guard let user = authResult ?.user else { return }
let isAnonymous = user.isAnonymous // true
let uid = user.uid
}
Anonymous Auth
let db = Firestore.firestore()
do {
_ = try db.collection(“users/(user.uid)/consumption/")
.addDocument(from: consumption)
}
catch {
print(“Error: (error.localizedDescription).")
}
Saving Data to Firestore
Sign in with Apple
let authUI = FUIAuth.defaultAuthUI()
authUI.shouldAutoUpgradeAnonymousUsers = true
authUI.providers = [
FUIGoogleAuth(),
FUIOAuth.appleAuthProvider()
]
return authUI.authViewController()
Sign in with Apple
Data Flow
Data Flow
• Property

• @State

• @Binding

• @ObservedObject

• @EnvironmentObject

• Sarah Reichelt: SwiftUI Data Flow
(bit.ly/SwiftUIDataFlow)
struct BarsView: View {
let bars: [Bar]
let max: Double
init(bars: [Bar]) {
self.bars = bars
self.max = bars.map { $0.value }.max() ?? 0
}
var body: some View {
GeometryReader { geometry in
HStack(alignment: .bottom, spacing: 0) {
ForEach(self.bars) { bar in
Rectangle()
.fill(bar.color)
.frame(width: 10,
height: CGFloat(bar.value) /
CGFloat(self.max) * geometry.size.height)
Data Flow - Property
struct MainView: View {
@State var selectedTab = 0
@EnvironmentObject var appState: AppState
var body: some View {
TabView(selection: $selectedTab) {
}
}
}
Data Flow - @State
class CoffeeListViewModel: ObservableObject {
@Published var coffees: [Coffee]
}
struct CoffeeListView: View {
@ObservedObject var viewModel: CoffeeListViewModel
var body: some View {
NavigationView {
List(viewModel.coffees) { coffee in
CoffeeCell(coffee: coffee)
}
.navigationBarTitle("Coffees")
}
}
}
Data Flow - @ObservableObject
class AppState: ObservableObject {
@Published var coffees = [Coffee]()
@Published var consumptions = [Consumption]()
}
let appState = AppState()
let contentView = MainView()
window.rootViewController =
UIHostingController(rootView: contentView.environmentObject(appState))
struct MainView: View {
@EnvironmentObject var appState: AppState
var body: some View {
HistoryView(viewModel: HistoryViewModel(consumption: appState.consumptions))
.tabItem { Image(systemName: “chart.bar.fill”)) }
}
}
Data Flow - @EnvironmentObject
Data Flow for Firebase Apps
MainViewAppState
[Coffee]
[Consumption]
User
...
Environment
CoffeeListView
CoffeeListVM
[Coffee]
Firestore
Demo 3
The Final App, Using Firebase
Conclusion
Conclusion
• Achieve great results in a short amount of time

• Documentation a bit lacking

• Great contributions from the community

• A number of things don’t work (yet)

• Fill the gaps with UIViewControllerRepresentable
Conclusion
• Work together well

• No critical issues so far

• Firebase team eager to hear from the community
+
❤
Thanks! Peter Friese, Developer Advocate, Google
@peterfriese
https://peterfriese.dev

https://medium.com/@peterfriese
https://medium.com/firebase-developers

Weitere ähnliche Inhalte

Was ist angesagt?

Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsLiam Cleary [MVP]
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Rob Windsor
 
A To-do Web App on Google App Engine
A To-do Web App on Google App EngineA To-do Web App on Google App Engine
A To-do Web App on Google App EngineMichael Parker
 
Usergrid Overview
Usergrid OverviewUsergrid Overview
Usergrid Overviewusergrid
 
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)NexThoughts Technologies
 
Salesforce Lightning Tips & Tricks
Salesforce Lightning Tips & Tricks Salesforce Lightning Tips & Tricks
Salesforce Lightning Tips & Tricks Thinqloud
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache UsergridDavid M. Johnson
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelPhil Wicklund
 
Creating a Custom PowerApp Connector using Azure Functions
Creating a Custom PowerApp Connector using Azure FunctionsCreating a Custom PowerApp Connector using Azure Functions
Creating a Custom PowerApp Connector using Azure FunctionsMurray Fife
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewRob Windsor
 
Open Source Mobile Backend on Cassandra
Open Source Mobile Backend on CassandraOpen Source Mobile Backend on Cassandra
Open Source Mobile Backend on CassandraEd Anuff
 
Try!Swift India 2017: All you need is Swift
Try!Swift India 2017: All you need is SwiftTry!Swift India 2017: All you need is Swift
Try!Swift India 2017: All you need is SwiftChris Bailey
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...SharePoint Saturday NY
 
Eventbus Library and How Does it Work?
Eventbus Library and How Does it Work?Eventbus Library and How Does it Work?
Eventbus Library and How Does it Work?InnovationM
 
SharePoint solution developer exam 70-488
SharePoint solution developer exam 70-488SharePoint solution developer exam 70-488
SharePoint solution developer exam 70-488Ahmed Tawfik
 
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...Mahmoud Hamed Mahmoud
 

Was ist angesagt? (20)

Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
 
A To-do Web App on Google App Engine
A To-do Web App on Google App EngineA To-do Web App on Google App Engine
A To-do Web App on Google App Engine
 
Usergrid Overview
Usergrid OverviewUsergrid Overview
Usergrid Overview
 
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
 
Salesforce Lightning Tips & Tricks
Salesforce Lightning Tips & Tricks Salesforce Lightning Tips & Tricks
Salesforce Lightning Tips & Tricks
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache Usergrid
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object Model
 
Creating a Custom PowerApp Connector using Azure Functions
Creating a Custom PowerApp Connector using Azure FunctionsCreating a Custom PowerApp Connector using Azure Functions
Creating a Custom PowerApp Connector using Azure Functions
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development Overview
 
Open Source Mobile Backend on Cassandra
Open Source Mobile Backend on CassandraOpen Source Mobile Backend on Cassandra
Open Source Mobile Backend on Cassandra
 
Try!Swift India 2017: All you need is Swift
Try!Swift India 2017: All you need is SwiftTry!Swift India 2017: All you need is Swift
Try!Swift India 2017: All you need is Swift
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
Html indexed db
Html indexed dbHtml indexed db
Html indexed db
 
Eventbus Library and How Does it Work?
Eventbus Library and How Does it Work?Eventbus Library and How Does it Work?
Eventbus Library and How Does it Work?
 
SharePoint solution developer exam 70-488
SharePoint solution developer exam 70-488SharePoint solution developer exam 70-488
SharePoint solution developer exam 70-488
 
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 

Ähnlich wie Rapid Application Development with SwiftUI and Firebase

Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebasePeter Friese
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien
 
Going Serverless with Azure Functions
Going Serverless with Azure FunctionsGoing Serverless with Azure Functions
Going Serverless with Azure FunctionsShahed Chowdhuri
 
Code First with Serverless Azure Functions
Code First with Serverless Azure FunctionsCode First with Serverless Azure Functions
Code First with Serverless Azure FunctionsJeremy Likness
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013Kiril Iliev
 
Medium TechTalk — iOS
Medium TechTalk — iOSMedium TechTalk — iOS
Medium TechTalk — iOSjimmyatmedium
 
Saving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroSaving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroQuickBase, Inc.
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbsAWS Chicago
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Introduction to using jQuery with SharePoint
Introduction to using jQuery with SharePointIntroduction to using jQuery with SharePoint
Introduction to using jQuery with SharePointRene Modery
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopJimmy Guerrero
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIRob Windsor
 
Spring 3 - An Introduction
Spring 3 - An IntroductionSpring 3 - An Introduction
Spring 3 - An IntroductionThorsten Kamann
 

Ähnlich wie Rapid Application Development with SwiftUI and Firebase (20)

Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
 
Going Serverless with Azure Functions
Going Serverless with Azure FunctionsGoing Serverless with Azure Functions
Going Serverless with Azure Functions
 
Code First with Serverless Azure Functions
Code First with Serverless Azure FunctionsCode First with Serverless Azure Functions
Code First with Serverless Azure Functions
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
 
Medium TechTalk — iOS
Medium TechTalk — iOSMedium TechTalk — iOS
Medium TechTalk — iOS
 
Saving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroSaving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio Haro
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Introduction to using jQuery with SharePoint
Introduction to using jQuery with SharePointIntroduction to using jQuery with SharePoint
Introduction to using jQuery with SharePoint
 
WebGUI Developers Workshop
WebGUI Developers WorkshopWebGUI Developers Workshop
WebGUI Developers Workshop
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST API
 
Spring 3 - An Introduction
Spring 3 - An IntroductionSpring 3 - An Introduction
Spring 3 - An Introduction
 

Mehr von Peter Friese

Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsPeter Friese
 
Firebase & SwiftUI Workshop
Firebase & SwiftUI WorkshopFirebase & SwiftUI Workshop
Firebase & SwiftUI WorkshopPeter Friese
 
Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsPeter Friese
 
Firebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroesFirebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroesPeter Friese
 
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift LeedsPeter Friese
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in SwiftPeter Friese
 
Firebase for Apple Developers
Firebase for Apple DevelopersFirebase for Apple Developers
Firebase for Apple DevelopersPeter Friese
 
Building Apps with SwiftUI and Firebase
Building Apps with SwiftUI and FirebaseBuilding Apps with SwiftUI and Firebase
Building Apps with SwiftUI and FirebasePeter Friese
 
Five Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase AuthFive Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase AuthPeter Friese
 
Building High-Quality Apps for Google Assistant
Building High-Quality Apps for Google AssistantBuilding High-Quality Apps for Google Assistant
Building High-Quality Apps for Google AssistantPeter Friese
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Peter Friese
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on GoogleBuilding Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on GooglePeter Friese
 
What's new in Android Wear 2.0
What's new in Android Wear 2.0What's new in Android Wear 2.0
What's new in Android Wear 2.0Peter Friese
 
Google Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinGoogle Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinPeter Friese
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android WearPeter Friese
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services RockPeter Friese
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android WearPeter Friese
 
Google+ for Mobile Apps on iOS and Android
Google+ for Mobile Apps on iOS and AndroidGoogle+ for Mobile Apps on iOS and Android
Google+ for Mobile Apps on iOS and AndroidPeter Friese
 
Cross-Platform Authentication with Google+ Sign-In
Cross-Platform Authentication with Google+ Sign-InCross-Platform Authentication with Google+ Sign-In
Cross-Platform Authentication with Google+ Sign-InPeter Friese
 
Bring Back the Fun to Testing Android Apps with Robolectric
Bring Back the Fun to Testing Android Apps with RobolectricBring Back the Fun to Testing Android Apps with Robolectric
Bring Back the Fun to Testing Android Apps with RobolectricPeter Friese
 

Mehr von Peter Friese (20)

Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI Components
 
Firebase & SwiftUI Workshop
Firebase & SwiftUI WorkshopFirebase & SwiftUI Workshop
Firebase & SwiftUI Workshop
 
Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI Components
 
Firebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroesFirebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroes
 
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Firebase for Apple Developers
Firebase for Apple DevelopersFirebase for Apple Developers
Firebase for Apple Developers
 
Building Apps with SwiftUI and Firebase
Building Apps with SwiftUI and FirebaseBuilding Apps with SwiftUI and Firebase
Building Apps with SwiftUI and Firebase
 
Five Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase AuthFive Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase Auth
 
Building High-Quality Apps for Google Assistant
Building High-Quality Apps for Google AssistantBuilding High-Quality Apps for Google Assistant
Building High-Quality Apps for Google Assistant
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on GoogleBuilding Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
What's new in Android Wear 2.0
What's new in Android Wear 2.0What's new in Android Wear 2.0
What's new in Android Wear 2.0
 
Google Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinGoogle Fit, Android Wear & Xamarin
Google Fit, Android Wear & Xamarin
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services Rock
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 
Google+ for Mobile Apps on iOS and Android
Google+ for Mobile Apps on iOS and AndroidGoogle+ for Mobile Apps on iOS and Android
Google+ for Mobile Apps on iOS and Android
 
Cross-Platform Authentication with Google+ Sign-In
Cross-Platform Authentication with Google+ Sign-InCross-Platform Authentication with Google+ Sign-In
Cross-Platform Authentication with Google+ Sign-In
 
Bring Back the Fun to Testing Android Apps with Robolectric
Bring Back the Fun to Testing Android Apps with RobolectricBring Back the Fun to Testing Android Apps with Robolectric
Bring Back the Fun to Testing Android Apps with Robolectric
 

Kürzlich hochgeladen

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 

Kürzlich hochgeladen (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 

Rapid Application Development with SwiftUI and Firebase

  • 1. Rapid Application Development with SwiftUI and Firebase Peter Friese, Developer Advocate, Google @peterfriese 🔥
  • 2.
  • 3. Demo 1 Kaffeinated - A coffee tracking app
  • 4.
  • 5.
  • 6. SwiftUI • A declarative way to build your UI • Everything is a view • Every SwiftUI view is a struct • You build UIs by composing views • Views are a function of their state Better state management!
  • 7. struct ContentView: View { var body: some View { Text("Hello, World!") } } SwiftUI Views
  • 8. Demo 2 Building a List From Scratch
  • 9.
  • 10.
  • 11.
  • 12. Improve app quality Crashlytics Performance Monitoring Test Lab App Distribution Grow your app Analytics Predictions Cloud Messaging Remote Config A/B Testing Dynamic Links In-app Messaging Build better apps Auth Cloud Functions Cloud Firestore Hosting ML Kit Realtime Database Cloud Storage bit.ly/what-is-firebase
  • 13.
  • 14. Mobile Databases - The Hard Way Database MongoDB, Postgres, MySQL, etc API Server REST API on top of database Auth Service Protects the API server Sync Logic REST API calls, caches, etc SQLite Store data offline
  • 15. Cross-platform? You're going to have to write the same code multiple times!
  • 17.
  • 21. collection("restaurants"). where("city", " ==", "Cairo"). orderBy(“rating”, "desc").limit(10) Here ya go!
  • 22. Add Firebase to Your iOS Project 1. Create a new Firebase project 2. Register your iOS app 3. Download configuration file 4. Install the Firebase Cocoapod 5. Call FirebaseApp.configure()
  • 24. Fetching Data from Firestore
  • 25. db.collection("coffees").addSnapshotListener { (querySnapshot, error) in var coffees = [Coffee]() querySnapshot ?.documents.forEach { document in let coffeeName = document.data()["name"] as? String ?? "" let shortDescription = document.data()["shortDescription"] as? String ?? "" let description = document.data()["description"] as? String ?? "" let caffeineAmount = document.data()["caffeineAmount"] as? Int ?? 0 let coffee = Coffee(name: coffeeName, shortDescription: shortDescription, description: description, caffeineAmount: caffeineAmount) coffees.append(coffee) } self.coffees = coffees } Fetching Data from Firestore
  • 26.
  • 27. Firestore & Codable • One of our most-requested and longest-running feature requests • Released on October 22nd, 2019 • Makes fetching and writing much easier
  • 28. db.collection("coffees").addSnapshotListener { (querySnapshot, error) in var coffees = [Coffee]() querySnapshot ?.documents.forEach { document in let coffeeName = document.data()["name"] as? String ?? "" let shortDescription = document.data()["shortDescription"] as? String ?? "" let description = document.data()["description"] as? String ?? "" let caffeineAmount = document.data()["caffeineAmount"] as? Int ?? 0 let coffee = Coffee(name: coffeeName, shortDescription: shortDescription, description: description, caffeineAmount: caffeineAmount) coffees.append(coffee) } self.coffees = coffees } Fetching Data - w/o Codable
  • 29. // Model struct Coffee: Codable, Identifiable { @DocumentID var id: String? var name: String var shortDescription: String var description: String } // Elsewhere, fetch our data: db.collection("coffees").addSnapshotListener { (querySnapshot, error) in if let querySnapshot = querySnapshot { self.coffees = querySnapshot.documents.compactMap { document -> Coffee? in try? document.data(as: Coffee.self) } } } Fetching Data - w/ Codable
  • 30. Saving Data to Firestore
  • 31. let db = Firestore.firestore() do { _ = try db.collection(“users/(user.uid)/consumption/") .addDocument(from: consumption) } catch { print(“Error: (error.localizedDescription).") } Saving Data to Firestore
  • 32. let db = Firestore.firestore() do { _ = try db.collection(“users/(user.uid)/consumption/") .addDocument(from: consumption) } catch { print(“Error: (error.localizedDescription).") } Saving Data to Firestore We didn’t sign in, so what’s this kind of magic?
  • 34. Auth.auth().signInAnonymously() { (authResult, error) in guard let user = authResult ?.user else { return } let isAnonymous = user.isAnonymous // true let uid = user.uid } Anonymous Auth
  • 35. let db = Firestore.firestore() do { _ = try db.collection(“users/(user.uid)/consumption/") .addDocument(from: consumption) } catch { print(“Error: (error.localizedDescription).") } Saving Data to Firestore
  • 36. Sign in with Apple
  • 37. let authUI = FUIAuth.defaultAuthUI() authUI.shouldAutoUpgradeAnonymousUsers = true authUI.providers = [ FUIGoogleAuth(), FUIOAuth.appleAuthProvider() ] return authUI.authViewController() Sign in with Apple
  • 39. Data Flow • Property • @State • @Binding • @ObservedObject • @EnvironmentObject • Sarah Reichelt: SwiftUI Data Flow (bit.ly/SwiftUIDataFlow)
  • 40. struct BarsView: View { let bars: [Bar] let max: Double init(bars: [Bar]) { self.bars = bars self.max = bars.map { $0.value }.max() ?? 0 } var body: some View { GeometryReader { geometry in HStack(alignment: .bottom, spacing: 0) { ForEach(self.bars) { bar in Rectangle() .fill(bar.color) .frame(width: 10, height: CGFloat(bar.value) / CGFloat(self.max) * geometry.size.height) Data Flow - Property
  • 41. struct MainView: View { @State var selectedTab = 0 @EnvironmentObject var appState: AppState var body: some View { TabView(selection: $selectedTab) { } } } Data Flow - @State
  • 42. class CoffeeListViewModel: ObservableObject { @Published var coffees: [Coffee] } struct CoffeeListView: View { @ObservedObject var viewModel: CoffeeListViewModel var body: some View { NavigationView { List(viewModel.coffees) { coffee in CoffeeCell(coffee: coffee) } .navigationBarTitle("Coffees") } } } Data Flow - @ObservableObject
  • 43. class AppState: ObservableObject { @Published var coffees = [Coffee]() @Published var consumptions = [Consumption]() } let appState = AppState() let contentView = MainView() window.rootViewController = UIHostingController(rootView: contentView.environmentObject(appState)) struct MainView: View { @EnvironmentObject var appState: AppState var body: some View { HistoryView(viewModel: HistoryViewModel(consumption: appState.consumptions)) .tabItem { Image(systemName: “chart.bar.fill”)) } } } Data Flow - @EnvironmentObject
  • 44. Data Flow for Firebase Apps MainViewAppState [Coffee] [Consumption] User ... Environment CoffeeListView CoffeeListVM [Coffee] Firestore
  • 45. Demo 3 The Final App, Using Firebase
  • 46.
  • 47.
  • 49. Conclusion • Achieve great results in a short amount of time • Documentation a bit lacking • Great contributions from the community • A number of things don’t work (yet) • Fill the gaps with UIViewControllerRepresentable
  • 50. Conclusion • Work together well • No critical issues so far • Firebase team eager to hear from the community +
  • 51.
  • 52. Thanks! Peter Friese, Developer Advocate, Google @peterfriese https://peterfriese.dev https://medium.com/@peterfriese https://medium.com/firebase-developers