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

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

Forums > SwiftUI

Hi I'm building a timer app and I'm adding app icons but I got this message: 'Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure' This is after the struct and as a 'Settings View' Here's the code below Can anyone help, thanks.

.navigationBarItems( trailing: NavigationLink( destination: Form { //Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure Section( header: HStack { Image(systemName: "switch.2") Text("General Preferences") } ) { HStack { Image(systemName: "timer") Text("Default Time - (formatTime(time: Int(defaultMinutes))):(formatTime(time: Int(defaultSeconds)))") Spacer() Button(action: { withAnimation(.easeInOut) { if !isTimerActive && !isCountingActive { withAnimation(.easeInOut) { seconds = 1 minutes = 0 isTimerActive = true isCountingActive = true } } defaultTimeChange.toggle() } }) { if defaultTimeChange { Text("Done") } else { Text("Edit") } } } if defaultTimeChange { Stepper(value: $defaultSeconds, in: 0...59) { Text("Seconds") } Stepper(value: $defaultMinutes, in: 0...59) { Text("Minutes") } } HStack { Image(systemName: "speaker.wave.2.fill") Picker("Finished Sound", selection: $selectedSound) { ForEach(sounds, id: .self) { Text($0) } } .onChange(of: selectedSound) { value in if value != "None" { playAudio(fileName: selectedSound) } } } HStack { Image("App Icon", systemName: "square.dashed") Picker(selection: $activeAppIcon) { let customIcons: [String] = ["AppIcon", "AppIcon2", "AppIcon3", "AppIcon4"] ForEach(customIcons, id: .self) {icon in Text(icon) .tag(icon) } } } .onChange(of: activeAppIcon) { newValue in UIApplication.shared.setAlternateIconName(newValue) } } Section( header: HStack { Image(systemName: "paintpalette") Text("Colour Preferences") } ) {

                                Picker("\(Image(systemName: "circle.lefthalf.fill")) Light Colour Set", selection: $selectedLightColourSet) {
                                    ForEach(colourSets, id: \.self) { colour in
                                        HStack {
                                            Text(colour)
                                            Spacer()
                                            ZStack {
                                                Capsule()
                                                    .foregroundColor(.gray.opacity(0.25))
                                                    .frame(width: 140, height: 40)
                                                HStack {
                                                    Image(systemName: "play.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "play"))
                                                    Image(systemName: "pause.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "pause"))
                                                    Image(systemName: "backward.end.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "cancel"))
                                                    Image(systemName: "record.circle.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "stroke"))
                                                }
                                            }
                                        }
                                    }
                                }
                                Picker("\(Image(systemName: "circle.righthalf.fill")) Dark Colour Set", selection: $selectedDarkColourSet) {
                                    ForEach(colourSets, id: \.self) { colour in
                                        HStack {
                                            Text(colour)
                                            Spacer()
                                            ZStack {
                                                Capsule()
                                                    .foregroundColor(.gray.opacity(0.25))
                                                    .frame(width: 140, height: 40)
                                                HStack {
                                                    Image(systemName: "play.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "play"))
                                                    Image(systemName: "pause.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "pause"))
                                                    Image(systemName: "backward.end.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "cancel"))
                                                    Image(systemName: "record.circle.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "stroke"))
                                                }
                                            }
                                        }
                                    }
                                }

                                Toggle(isOn: $changeBGColour) {
                                    HStack {
                                        Image(systemName: "paintbrush.fill")
                                        Text("Change Background Colour")
                                    }
                                }
                                .onChange(of: changeBGColour) { value in
                                    if value == true {
                                        BGColourPopover.toggle()
                                    }
                                }
                                .alert("The background will now change when counting down.", isPresented: $BGColourPopover) {
                                    Button("Ok", role: .cancel) { }
                                }
                            }
                            Section(
                                header: HStack {
                                    Image(systemName: "hands.clap")
                                    Text("Credits")
                                },
                                footer: Text("Copyright © 2022 --- .\nAll rights reserved.")
                            ) {
                                HStack {
                                    Image(systemName: "ladybug")
                                    Text("Report Bug")
                                    Spacer()
                                    Button("\(Image(systemName: "mail"))") {
                                        presentMailCompose(type: "Bug")
                                    }
                                }
                                HStack {
                                    Image(systemName: "plus.rectangle")
                                    Text("Request Feature")
                                    Spacer()
                                    Button("\(Image(systemName: "mail"))") {
                                        presentMailCompose(type: "Feature")
                                    }
                                }
                                HStack {
                                    Image(systemName: "keyboard.macwindow")
                                    Text("Engineered by ---")
                                    Spacer()
                                    Button("\(Image(systemName: "hand.tap"))") {
                                        secretAlert = true
                                    }
                                    .alert("PS. Try tapping the ring 5 times!", isPresented: $secretAlert) {
                                        Button("Ok", role: .cancel) { }
                                    }
                                }
                            }
                        }
                        .navigationBarTitle("Settings"),
                    label: {
                        Image(systemName: "gearshape")
                    }
                )
        )

1      

A lot of times, this error is because you have missed a closing brace or closing parenthesis somewhere. It's hard to see if that is the case with the format the first half of your code is in, but would still probably be hard to see even if it were all formatted properly.

But in this case, I think it might have to do with the way you are calling your Section initializers. The trailing closure syntax will work when the final parameter(s) is (are) closure types. But, they must still be listed in the correct order that they are given in the parameter list. I don't think that Section has an initializer where content is listed as the final parameter. The header and footer parameters would always come after it. So, you can't list those two parameters inside the parenthesis, and then have the content come in as a trailing closure at the end.

This is the definition of the initializer that you are trying to use.

init(content: () -> Content, header: () -> Parent, footer: () -> Footer)

Try setting up your sections this way instead, so that the parameters are all listed as trailing closures in the correct order.

Section {
    //Content code here
} header: {
    //Header code here
} footer: {
    //Footer code here
}

2      

Just as another example to show you what I'm talking about. You might have seen an initializer for a VStack that gets called like this before...

VStack(alignment: .leading) {
    //Content code here
}

In this case, we are allowed to list the alignment parameter inside the parenthesis, while still listing content in a trailing closure, because if we look at the definition of this initializer alignment is listed before content in the parameter list.

init(alignment: HorizontalAlignment, spacing: CGFloat?, content: () -> Content)

The spacing and alignment parameters can also be ignored, because they actually have default values.

1      

Here's the code if it helps.

`import SwiftUI import MessageUI import AVFoundation import UserNotifications

struct TimerView: View { let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

@State var isTimerActive = false
@State var isCountingActive = false

@State var seconds = 10
@State var minutes = 0
@State var defaultSeconds = 10
@State var defaultMinutes = 0
@State var defaultTimeChange: Bool = false

@State var originalSeconds = 10
@State var currentSeconds = 10
@State var ring = 1.0
@State var toTake = 0.1
@State var gradientOn: Bool = false
@State var secretAlert: Bool = false

@State var changeBGColour: Bool = false
@State var BGColourPopover: Bool = false
@State var randomColor: Color = .red

@State var audioPlayer: AVAudioPlayer?
@State var selectedSound = "Default"
let sounds = ["Default", "Default 2", "Timer Notify"]

let mailComposeDelegate = MailDelegate()

@AppStorage("active_icon") var activeAppIcon: String = "AppIcon"

@Environment(\.colorScheme) var colourScheme
@State var selectedLightColourSet = "Light Default"
@State var selectedDarkColourSet = "Dark Default"

let colourSets = [
    "Light Default", "Pastel", "Cool", "Classic", "Black",
    "Dark Default", "Neon", "Night Owl", "Sunset", "White"
]

let lightColourSet: [String: Color] = [
    "play": .mint,
    "pause": Color(#colorLiteral(red: 0.5254901051521301, green: 0.30980387330055237, blue: 0.9960787892341614, alpha: 1.0)),
    "cancel": .red,
    "stroke": .blue
]

let pastelColourSet: [String: Color] = [
    "play": Color(#colorLiteral(red: 0.7784313559532166, green: 0.6843138337135315, blue: 0.8313726782798767, alpha: 1.0)),
    "pause": Color(#colorLiteral(red: 0.9686276316642761, green: 0.758823573589325, blue: 0.8392156958580017, alpha: 1.0)),
    "cancel": Color(#colorLiteral(red: 0.48627424240112305, green: 0.5882355570793152, blue: 0.7823531627655029, alpha: 1.0)),
    "stroke": Color(#colorLiteral(red: 0.699999988079071, green: 0.8509804010391235, blue: 0.7980391979217529, alpha: 1.0))
]

let coolColourSet: [String: Color] = [
    "play": Color(#colorLiteral(red: 0.250980406999588, green: 0.32156866788864136, blue: 0.5098039507865906, alpha: 1.0)),
    "pause": Color(#colorLiteral(red: 0.16862738132476807, green: 0.21568626165390015, blue: 0.2941175699234009, alpha: 1.0)),
    "cancel": Color(#colorLiteral(red: 0.8156865239143372, green: 0.1921570897102356, blue: 0.38039207458496094, alpha: 1.0)),
    "stroke": Color(#colorLiteral(red: 0.09019533544778824, green: 0.5411766171455383, blue: 0.5803923010826111, alpha: 1.0))
]

let classicColourSet: [String: Color] = [
    "play": .green,
    "pause": .orange,
    "cancel": .black,
    "stroke": .orange
]

let blackColourSet: [String: Color] = [
    "play": .black,
    "pause": .black,
    "cancel": .black,
    "stroke": .black
]

let darkColourSet: [String: Color] = [
    "play": Color(#colorLiteral(red: 0.003918447997421026, green: 0.7803922891616821, blue: 0.9882356524467468, alpha: 1.0)),
    "pause": .white,
    "cancel": .red,
    "stroke": .pink
]

let neonColourSet: [String: Color] = [
    "play": Color(#colorLiteral(red: 0.10887768119573593, green: 1.0000001192092896, blue: 0.10887082666158676, alpha: 1.0)),
    "pause": Color(#colorLiteral(red: 0.3204635977745056, green: 0.9998816847801208, blue: 1.000000238418579, alpha: 1.0)),
    "cancel": Color(#colorLiteral(red: 0.9910205006599426, green: 1.0000001192092896, blue: 0.04019148647785187, alpha: 1.0)),
    "stroke": Color(#colorLiteral(red: 1.0000003576278687, green: 0.12729215621948242, blue: 0.9811344742774963, alpha: 1.0))
]

let nightowlColourSet: [String: Color] = [
    "play": Color(#colorLiteral(red: 0.4432700574398041, green: 0.057988740503787994, blue: 1.0000001192092896, alpha: 1.0)),
    "pause": Color(#colorLiteral(red: 0.3215680718421936, green: 0.8392159342765808, blue: 0.9882352948188782, alpha: 1.0)),
    "cancel": Color(#colorLiteral(red: 0.9052000641822815, green: 0.4251731038093567, blue: 0.11207173019647598, alpha: 0.6875)),
    "stroke": Color(#colorLiteral(red: 0.9931392073631287, green: 1.000000238418579, blue: 0.26665163040161133, alpha: 1.0))
]

let sunsetColourSet: [String: Color] = [
    "play": Color(#colorLiteral(red: 0.9353944659233093, green: 0.37844473123550415, blue: 1.000000238418579, alpha: 1.0)),
    "pause": Color(#colorLiteral(red: 0.9960785508155823, green: 0.7058826088905334, blue: 0.24705874919891357, alpha: 1.0)),
    "cancel": Color(#colorLiteral(red: 1.0000004768371582, green: 0.25098052620887756, blue: 0.08235275000333786, alpha: 1.0)),
    "stroke": Color(#colorLiteral(red: 1.0000001192092896, green: 0.7725490927696228, blue: 0.6705884337425232, alpha: 1.0))
]

let whiteColourSet: [String: Color] = [
    "play": .white,
    "pause": .white,
    "cancel": .white,
    "stroke": .white
]

var body: some View {
    NavigationView {
        ZStack {
            Spacer()
            if changeBGColour {
                randomColor.opacity(0.1).edgesIgnoringSafeArea(.all)
            }
            VStack(spacing: 25) {
                ZStack {
                    Circle()
                        .stroke(
                            Color.gray.opacity(0.1),
                            style: StrokeStyle(
                                lineWidth: 35, lineCap: .round
                            )
                        )
                    Circle()
                        .trim(from: 0, to: isTimerActive ? ring: 1)
                        .stroke(
                            gradientOn ?
                            (
                                AngularGradient(gradient: Gradient(colors: [Color.red, Color.orange, Color.yellow, Color.green, Color.blue, Color.indigo, Color.purple]), center: .center)
                            ) : (
                                AngularGradient(gradient: Gradient(colors: [colourSetButton(button: "stroke")]), center: .center)
                            ),
                            style: StrokeStyle(
                                lineWidth: 35, lineCap: .round
                            )
                        )
                        .rotationEffect(.init(degrees: -90))
                        .onTapGesture(count: 5) {
                            gradientOn.toggle()
                        }

                    if !isTimerActive {
                        VStack {
                            Text("\(formatTime(time: Int(minutes))):\(formatTime(time: Int(seconds)))")
                                .foregroundColor(colourScheme == .light ? .black:.white)
                                .font(.system(size:34))

                            HStack {
                                Stepper(value: $seconds, in: 0...59) {
                                    Text("Seconds")
                                }
                                .padding(.horizontal, 50)
                            }
                            HStack {
                                Stepper(value: $minutes, in: 0...59) {
                                    Text("Minutes")
                                }
                                .padding(.horizontal, 50)
                            }
                        }
                    } else if isTimerActive {
                        Text("\(formatTime(time: Int(minutes))):\(formatTime(time: Int(seconds)))")
                            .foregroundColor(colourScheme == .light ? .black:.white)
                            .font(.system(size:34))
                    }
                }
                .frame(width: 280, height: 280)
                .padding()

                HStack(spacing: 25) {
                    Button(
                        action: {
                            if !isTimerActive && !isCountingActive {
                                withAnimation(.easeInOut) {
                                    isTimerActive = true
                                    isCountingActive = true
                                }
                                originalSeconds = (minutes * 60) + seconds
                                toTake = 1.0 / Double(originalSeconds)
                            } else if isTimerActive && isCountingActive {
                                if (seconds + (minutes * 60)) > 1 {
                                    withAnimation(.easeInOut) {
                                        isCountingActive = false
                                    }
                                }
                            } else if isTimerActive && !isCountingActive {
                                withAnimation(.easeInOut) {
                                    isCountingActive = true
                                }
                            }
                        }) {
                            Label(
                                isTimerActive ? (isCountingActive ? "Pause": "Resume") : "Start",
                                systemImage: isTimerActive ? (isCountingActive ? "pause.fill": "play.fill") : "play.fill"
                            )
                                .foregroundStyle(
                                    gradientOn ? (
                                        LinearGradient(
                                            colors: [.red, .orange, .yellow, .green, .blue, .indigo, .purple],
                                            startPoint: .leading,
                                            endPoint: .trailing
                                        )
                                    ) : (
                                        LinearGradient(
                                            colors: [
                                                (
                                                    !isTimerActive && !isCountingActive && minutes == 0 && seconds == 0 ? .gray : (
                                                        isCountingActive ? (
                                                            colourSetButton(button: "pause")
                                                        ) : (
                                                            colourSetButton(button: "play")
                                                        )
                                                    )
                                                )
                                            ],
                                            startPoint: .leading,
                                            endPoint: .trailing
                                        )
                                    )
                                )
                                .padding(14)
                                .font(.title)
                        }
                        .disabled(!isTimerActive && !isCountingActive && minutes == 0 && seconds == 0 ? true:false)
                        .keyboardShortcut("p", modifiers: .command)

                    Button(
                        action: {
                            withAnimation(.easeInOut) {
                                isTimerActive = false
                                isCountingActive = false
                                ring = 1.0
                            }
                            seconds = defaultSeconds
                            minutes = defaultMinutes
                        }) {
                            Label("Cancel", systemImage: "backward.end.fill")
                                .foregroundStyle(
                                    gradientOn ? (
                                        LinearGradient(
                                            colors: [.red, .orange, .yellow, .green, .blue, .indigo, .purple],
                                            startPoint: .leading,
                                            endPoint: .trailing
                                        )
                                    ) : (
                                        LinearGradient(
                                            colors: [
                                                (
                                                    isTimerActive ? colourSetButton(button: "cancel"): .gray
                                                )
                                            ],
                                            startPoint: .leading,
                                            endPoint: .trailing
                                        )
                                    )
                                )
                                .padding(14)
                                .font(.title)
                        }
                        .disabled(isTimerActive ? false:true)
                        .keyboardShortcut("r", modifiers: .command)
                }
            }
            Spacer()
        }
        .onAppear {
            UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
                if success {
                } else if let error = error {
                    print(error.localizedDescription)
                }
            }
        }

1      

Here's the second part - it was too long to put in one comment

`.onReceive(timer) { time in guard isCountingActive else { return } currentSeconds = seconds + (minutes * 60)

            withAnimation {
                randomColor = Color(
                    red: .random(in: 0...1),
                    green: .random(in: 0...1),
                    blue: .random(in: 0...1)
                )
                ring -= toTake
            }

            if seconds > 0 {
                seconds -= 1
            } else if seconds == 0 && minutes > 0 {
                minutes -= 1
                seconds += 59
            } else if seconds == 0 && minutes == 0 {
                withAnimation {
                    isTimerActive = false
                    isCountingActive = false
                    seconds = defaultSeconds
                    minutes = defaultMinutes
                    ring = 1.0
                }
            }
        }

        .navigationBarItems(
            trailing:
                NavigationLink(
                    destination:
                        Form {
                            Section(
                                header: HStack {
                                    Image(systemName: "switch.2")
                                    Text("General Preferences")
                                }
                            ) {
                                HStack {
                                    Image(systemName: "timer")
                                    Text("Default Time - \(formatTime(time: Int(defaultMinutes))):\(formatTime(time: Int(defaultSeconds)))")
                                    Spacer()
                                    Button(action: {
                                        withAnimation(.easeInOut) {
                                            if !isTimerActive && !isCountingActive {
                                                withAnimation(.easeInOut) {
                                                    seconds = 1
                                                    minutes = 0
                                                    isTimerActive = true
                                                    isCountingActive = true
                                                }
                                            }
                                            defaultTimeChange.toggle()
                                        }
                                    }) {
                                        if defaultTimeChange {
                                            Text("Done")
                                        } else {
                                            Text("Edit")
                                        }
                                    }
                                }
                                if defaultTimeChange {
                                    Stepper(value: $defaultSeconds, in: 0...59) {
                                        Text("Seconds")
                                    }
                                    Stepper(value: $defaultMinutes, in: 0...59) {
                                        Text("Minutes")
                                    }
                                }
                                HStack {
                                    Image(systemName: "speaker.wave.2.fill")
                                    Picker("Finished Sound", selection: $selectedSound) {
                                        ForEach(sounds, id: \.self) {
                                            Text($0)
                                        }
                                    }
                                    .onChange(of: selectedSound) { value in
                                        if value != "None" {
                                            playAudio(fileName: selectedSound)
                                        }
                                    }
                                }
                                HStack {
                                    Image("App Icon", systemName: "square.dashed")
                                    Picker(selection: $activeAppIcon) {
                                        let customIcons: [String] = ["AppIcon", "AppIcon2", "AppIcon3", "AppIcon4"]
                                        ForEach(customIcons, id: \.self) {icon in
                                            Text(icon)
                                                .tag(icon)
                                        }
                                    }
                                }
                                .onChange(of: activeAppIcon) { newValue in
                                    UIApplication.shared.setAlternateIconName(newValue)
                                }
                            }
                            Section(
                                header: HStack {
                                    Image(systemName: "paintpalette")
                                    Text("Colour Preferences")
                                }
                            ) {

                                Picker("\(Image(systemName: "circle.lefthalf.fill")) Light Colour Set", selection: $selectedLightColourSet) {
                                    ForEach(colourSets, id: \.self) { colour in
                                        HStack {
                                            Text(colour)
                                            Spacer()
                                            ZStack {
                                                Capsule()
                                                    .foregroundColor(.gray.opacity(0.25))
                                                    .frame(width: 140, height: 40)
                                                HStack {
                                                    Image(systemName: "play.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "play"))
                                                    Image(systemName: "pause.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "pause"))
                                                    Image(systemName: "backward.end.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "cancel"))
                                                    Image(systemName: "record.circle.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "stroke"))
                                                }
                                            }
                                        }
                                    }
                                }
                                Picker("\(Image(systemName: "circle.righthalf.fill")) Dark Colour Set", selection: $selectedDarkColourSet) {
                                    ForEach(colourSets, id: \.self) { colour in
                                        HStack {
                                            Text(colour)
                                            Spacer()
                                            ZStack {
                                                Capsule()
                                                    .foregroundColor(.gray.opacity(0.25))
                                                    .frame(width: 140, height: 40)
                                                HStack {
                                                    Image(systemName: "play.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "play"))
                                                    Image(systemName: "pause.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "pause"))
                                                    Image(systemName: "backward.end.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "cancel"))
                                                    Image(systemName: "record.circle.fill")
                                                        .foregroundColor(settingsColourSet(selectedSet: colour, icon: "stroke"))
                                                }
                                            }
                                        }
                                    }
                                }

                                Toggle(isOn: $changeBGColour) {
                                    HStack {
                                        Image(systemName: "paintbrush.fill")
                                        Text("Change Background Colour")
                                    }
                                }
                                .onChange(of: changeBGColour) { value in
                                    if value == true {
                                        BGColourPopover.toggle()
                                    }
                                }
                                .alert("The background will now change when counting down.", isPresented: $BGColourPopover) {
                                    Button("Ok", role: .cancel) { }
                                }
                            }
                            Section(
                                header: HStack {
                                    Image(systemName: "hands.clap")
                                    Text("Credits")
                                },
                                footer: Text("Copyright © 2022 ---.\nAll rights reserved.")
                            ) {
                                HStack {
                                    Image(systemName: "ladybug")
                                    Text("Report Bug")
                                    Spacer()
                                    Button("\(Image(systemName: "mail"))") {
                                        presentMailCompose(type: "Bug")
                                    }
                                }
                                HStack {
                                    Image(systemName: "plus.rectangle")
                                    Text("Request Feature")
                                    Spacer()
                                    Button("\(Image(systemName: "mail"))") {
                                        presentMailCompose(type: "Feature")
                                    }
                                }
                                HStack {
                                    Image(systemName: "keyboard.macwindow")
                                    Text("Engineered by ---")
                                    Spacer()
                                    Button("\(Image(systemName: "hand.tap"))") {
                                        secretAlert = true
                                    }
                                    .alert("PS. Try tapping the ring 5 times!", isPresented: $secretAlert) {
                                        Button("Ok", role: .cancel) { }
                                    }
                                }
                            }
                        }
                        .navigationBarTitle("Settings"),
                    label: {
                        Image(systemName: "gearshape")
                    }
                )
        )
    }
    .navigationViewStyle(StackNavigationViewStyle())
}

func formatTime(time: Int) -> String {
    return time < 10 ? "0\(time)" : "\(time)"
}

func colourSetButton(button: String) -> Color {
    return colourSet()[button]!
}

func colourSet() -> [String: Color] {
    let cset = colourScheme == .light ? selectedLightColourSet: selectedDarkColourSet
    switch cset {
    case "Light Default":
        return lightColourSet
    case "Pastel":
        return pastelColourSet
    case "Cool":
        return coolColourSet
    case "Classic":
        return classicColourSet
    case "Black":
        return blackColourSet
    case "Dark Default":
        return darkColourSet
    case "Neon":
        return neonColourSet
    case "Night Owl":
        return nightowlColourSet
    case "Sunset":
        return sunsetColourSet
    case "White":
        return whiteColourSet
    default:
        return lightColourSet
    }
}

func settingsColourSet(selectedSet: String, icon: String) -> Color {
    func partA() -> [String: Color] {
        switch selectedSet {
        case "Light Default":
            return lightColourSet
        case "Pastel":
            return pastelColourSet
        case "Cool":
            return coolColourSet
        case "Classic":
            return classicColourSet
        case "Black":
            return blackColourSet
        case "Dark Default":
            return darkColourSet
        case "Neon":
            return neonColourSet
        case "Night Owl":
            return nightowlColourSet
        case "Sunset":
            return sunsetColourSet
        case "White":
            return whiteColourSet
        default:
            return lightColourSet
        }
    }
    return partA()[icon]!
}

func playAudio(fileName: String) {
    if let audioURL = Bundle.main.url(forResource: fileName, withExtension: "m4a") {
        do {
            try self.audioPlayer = AVAudioPlayer(contentsOf: audioURL)
            self.audioPlayer?.numberOfLoops = 0
            self.audioPlayer?.play()
        } catch {
            print("Couldn't play (\(fileName)) audio file. Error: \(error)")
        }
    } else {

    }
}

func notificationSound() -> UNNotificationSound {
    var sound = UNNotificationSound.default
    switch selectedSound {
    case "Default":
        sound = UNNotificationSound.default
    case "Default 2":
        sound = UNNotificationSound.defaultCritical
    case "Timer Notify":
        sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "\(selectedSound).m4a"))
    default:
        sound = UNNotificationSound.default
    }
    return sound
}

func addNotification() {
    let content = UNMutableNotificationContent()
    content.title = "Your timer has finished!"
    content.body = "Woohoo 🥳"
    content.sound = notificationSound()

    let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false))

    UNUserNotificationCenter.current().add(request)
}

class MailDelegate: NSObject, MFMailComposeViewControllerDelegate {
    func mailComposeController(_ controller: MFMailComposeViewController,
                               didFinishWith result: MFMailComposeResult,
                               error: Error?) {
        controller.dismiss(animated: true)
    }
}

func presentMailCompose(type: String) {
    guard MFMailComposeViewController.canSendMail() else {
        return
    }
    let vc = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
    let composeVC = MFMailComposeViewController()

    composeVC.mailComposeDelegate = mailComposeDelegate
    composeVC.setToRecipients(["---@icloud.com"])

    composeVC.setSubject(type == "Bug" ? "Bug Report": "Feature Request")
    composeVC.setMessageBody(type == "Bug" ? "<h>————————————————————————</h>\n<p>Application Name: \(Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String ?? "Unknown")</p><p>Application Version: \( Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String), Build \(Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String)</p><p>Model Name: \(UIDevice.current.model)</p><p>OS Version: \(UIDevice.current.systemName) \(UIDevice.current.systemVersion)</p><h4>Enter your bug report with screenshots (recommended) below this line.</h4><h>————————————————————————</h>" : "<h>————————————————————————</h>\n<p>Application Name: \(Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String ?? "Unknown")</p><h4>Enter your feature request with detail and any concepts/drawings below this line.</h4><h>————————————————————————</h>", isHTML: true)

    vc?.present(composeVC, animated: true)
}

} `

1      

I guess Section did have an initializer like the one you are using. But it is depricated now.

If you look on this page, and scroll down to the deprecated symbols part, you can see that there was an initializer that lists the header and footer before content. But it has been deprecated since iOS 13.

https://developer.apple.com/documentation/swiftui/section

init(header: Parent, footer: Footer, content: () -> Content)

So that may be what's causing a problem for you, but I'm not sure.

Another thing that you might be able to try is pressing Command + A to select all of the text in your file, then press Control + I to fix the indentation on the selected text. Then you might be able to see if there is a place where the indentation stops looking right, and see if there is a missing brace or something around that area.

1      

I've fixed the issue now, thanks for your help

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.