Welcome to the forum.
I tested your code (after completing missing parts and removing reference to unknown structure) and it works OK, both with Xcode 16.0ß2 and Xcode 15.0.1.
Are you sure you have declared var as State vars ?
Have you declared dismiss ?
Aren't you missing a closing curly bracket somewhere ?
Where exactly do you get the error ?
Please show the exact and complete code, as well as your configuration (Xcode version, system version…)
Here is the complete code I tested:
struct ContentView: View {
@State var companyName: String = ""
@State var role: String = ""
@State var location: String = ""
@State var yearlySalary: Double = 0
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
Form {
TextField("Company Name", text: $companyName)
TextField("Role", text: $role)
TextField("Location", text: $location)
TextField("Yearly Salary", value: $yearlySalary, format: .currency(code: "USD"))
.keyboardType(.decimalPad)
}
.navigationTitle("Add Application")
.navigationBarTitleDisplayMode(.large)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("back") {
dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("Save") {
// let appdata = ApplicationData(
// companyName: companyName,
// role: role,
// location: location,
// yearlySalary: yearlySalary,
// dateApplied: dateApplied,
// notes: notes)
// // Save the application data
dismiss()
}
}
}
}
}
}