≈207 tokens on demand. Your agent reads this file only when SKILL.md points to it.
Environment (iOS 17+)
environment(:) — NOT environmentObject(:)
✅ Modern Pattern
@Observable
class AppSettings {
var isDarkMode: Bool = false
}
// Inject into environment
struct MyApp: App {
@State private var settings = AppSettings()
var body: some Scene {
WindowGroup {
ContentView()
.environment(settings)
}
}
}
// Access in child view
struct SettingsView: View {
@Environment(AppSettings.self) private var settings
var body: some View {
Toggle("Dark Mode", isOn: $settings.isDarkMode)
}
}
❌ Deprecated Pattern
// NEVER use .environmentObject(_:) with @Observable
.environmentObject(settings)
// NEVER use @EnvironmentObject with @Observable
@EnvironmentObject var settings: AppSettings