UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Error Message Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure

Forums > SwiftUI

Hi I'm on Day 16 of 100 Days of SwiftUI and I'm following along in the video creating the code just as the Paul is showing but under "Form" in the Content I'm getting this error message "Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure"

I attached a screen shot too.

Can anyone assist?

import SwiftUI

struct ContentView: View { @State private var checkAmount = 0.0 @State private var numberOfPeople = 2 @State private var tipPercentage = 20

let tipPercentages = [10, 15, 20, 25, 0]

var body: some View {
    NavigationView {
        Form    { *Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure
            Section {
                TextField("Amount", value: $checkAmount, format:
                        .currency(code: Locale.current.currency.Code ?? "USD"))
                .keyboardType(.decimalPad)
                Picker("Number of people", selection: $numberOfPeople)
                ForEach(2..<100) {
                    Text("\($0) people")
                }
            }

            Section {
                Text(checkAmount, format: .currency(code:
                                                        Locale.current.currencyCode ?? "USD"))
            }
        }
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

}

Thanks!

2      

Locale.current.currency.Code ?? "USD"

should be:

Locale.current.currencyCode ?? "USD"

And you forgot an opening bracket { for your Picker. Add that and then you need to adjust all the rest of your incorrectly bracketed and indented code as well.

2      

Appreciate your help!

1      

Hello, I have the same issue. Here is my code.

import SwiftUI

struct ContentView: View { @State private var tasks = [Task]() @State private var showAddTask = false @State private var isSignedIn = false @State private var userID = ""

var body: some View {
    NavigationView {
        List {
            ForEach(tasks.filter { $0.userID == userID }) { task in
                TaskCell(task: task)
            }
            .onDelete(perform: delete)
        }
        .navigationBarTitle("Tasks")
        .navigationBarItems(trailing: Button(action: {
            self.showAddTask = true
        }) {
            Image(systemName: "plus")
        })
        .sheet(isPresented: $showAddTask) {
            AddTaskView(tasks: self.$tasks)
        }
    }
    .navigationViewStyle(StackNavigationViewStyle())
    .navigate(to: SignInView(), when: $isSignedIn)
}

func delete(at offsets: IndexSet) {
    tasks.remove(atOffsets: offsets)
}

}

struct TaskCell: View { var task: Task

var body: some View {
    HStack {
        VStack(alignment: .leading) {
            Text(task.title)
                .font(.headline)
            Text(task.category)
                .font(.subheadline)
        }
        Spacer()
        Text(task.formattedDate)
            .font(.subheadline)
    }
}

}

struct AddTaskView: View { @Binding var tasks: [Task] @State private var title = "" @State private var category = "" @State private var date = Date() @State private var reminder = false @State private var showDatePicker = false @State private var userID = ""

var body: some View {
    Form {
        TextField("Title", text: $title)
        TextField("Category", text: $category)
        Toggle(isOn: $reminder) {
            Text("Set Reminder")
        }
        if reminder {
            DatePicker(selection: $date, displayedComponents: .dateAndTime, label: { Text("Date") })
                .datePickerStyle(WheelDatePickerStyle())
        }
        Button(action: {
            let task = Task(title: self.title, category: self.category, date: self.date, reminder: self.reminder, userID: self.userID)
            self.tasks.append(task)
            self.title = ""
            self.category = ""
            self.reminder = false
            self.date = Date()
        }) {
            Text("Add Task")
        }
    }
}

func onAppear() {

    userID = UserDefaults.standard.string(forKey: "userID") ?? ""
}

}

struct Task: Identifiable { var id: String { return title } var title: String var category: String var date: Date var reminder: Bool var userID: String

var formattedDate: String {
    let formatter = DateFormatter()
    formatter.dateStyle = .medium
    formatter.timeStyle = .short
    return formatter.string(from: date)
}

}

1      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.