Dev Notes

Dev Notes: February 7 - 21, 2025

Work

Cannot find $observable in scope

Today I learned that you need @Binding to fix the compiler error Cannot find $observable in scope.

var body: some View {
    @Bindable var authObservable = authObservable
}

Side Projects

Timers

I learned how to use timers in SwiftUI. For example, I want to display a launcher view in 3 seconds and then proceed to the next View().

@State private var timerCount = 0
@State private var exitFromLauncher = false
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

In our view:

var body: some View {
	if exitFromLauncher {
		// go to HomeView()
	} else {
		// Launcher UI
		ZStack {
		}
		.onReceive(timer) { input in
			if timerCount < 3 {
               timerCount += 1
        }
        if timerCount == 3 {
           exitFromLauncher = true
           timer.upstream.connect().cancel()
        }
      }
   }
}