I'm trying to use the new Swift Macros using @Observable and @Environment with the following code:
import SwiftUI
import Observation
@Observable class Note {
var text = ""
}
struct ContentView: View {
@State var note = Note()
var body: some View {
FormView()
.environment(note)
}
}
struct FormView: View {
@Environment(Note.self) var note
var body: some View {
Form {
TextField("write here", text: $note.text)
}
}
}
However, it's unable to build with the following error:
Cannot find '$note' in scope
Removing the $
in $note
results in:
Cannot convert value of type 'String' to expected argument type 'Binding<String>'