Skip to content

Instantly share code, notes, and snippets.

View haIIux's full-sized avatar
💭
learn. code. test. repeat.

Rob haIIux

💭
learn. code. test. repeat.
View GitHub Profile
@haIIux
haIIux / MediumArticleApp.swift
Last active March 2, 2022 21:14
Firebase Initialization - Swift
import SwiftUI
import Firebase
@main
struct MediumArticleApp: App {
init() {
FirebaseApp.configure()
}
@haIIux
haIIux / AuthViewModel.swift
Last active March 2, 2022 18:17
Firebase authentication view model creation.
import Firebase
// MARK: - Create our class of type ObservableObject which will allow us to access @Published variables we will create later.
class AuthViewModel: ObservableObject {
// MARK: - We're going to create two private let's, remember that let's are constants and cannot be mutated. Private means that we can only access those lets here in this file and no where else. The auth variable allows us to access Firebase Authentication methods and such, the firestore will allow us to access the Firestore ones.
private let auth = Auth.auth()
private let firestore = Firestore.firestore()
// MARK: - This is our registration function which allows us to simultaneously create a user within the authentication system and a entry within our Firestore database which allows for saving additional information.
@haIIux
haIIux / ContentView.swift
Created March 2, 2022 21:06
Firebase authentication intial view setup.
// Main App File.
import SwiftUI
import Firebase
@main
struct MediumArticleApp: App {
@StateObject var authViewModel = AuthViewModel()
init() {
FirebaseApp.app()
}