Skip to content

Instantly share code, notes, and snippets.

View shawnkoh's full-sized avatar

Shawn Koh shawnkoh

View GitHub Profile
@shawnkoh
shawnkoh / ExampleApp.swift
Created May 25, 2021 07:19
How to check if SwiftUI previews are running
import SwiftUI
@main
struct ExampleApp: App {
init() {
if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
// SwiftUI Preview is running.
// Do nothing.
} else {
FirebaseApp.configure()
@shawnkoh
shawnkoh / ExampleApp.swift
Last active May 25, 2021 07:11
How to stop SwiftUI Previews from crashing when using Firebase
protocol FirebaseService {
func configure()
}
class RealFirebaseService: FirebaseService {
func configure() {
FirebaseApp.configure()
let settings = FirestoreSettings()
Firestore.firestore().settings = settings
}
@shawnkoh
shawnkoh / ExampleApp.swift
Created May 25, 2021 03:29
Typical Firebase setup for a SwiftUI App
import SwiftUI
@main
struct ExampleApp: App {
init() {
FirebaseApp.configure()
let settings = FirestoreSettings()
Firestore.firestore().settings = settings
}
// MARK: - UseCases
struct InputData {}
protocol InputBoundary {
func doSomething(inputData: InputData, presenter: OutputBoundary)
}
protocol OutputBoundary {
var viewModel: ViewModel { get }