Xcode Invaild declaration of

I’m building an app using Xcode, and I’m running into Invaild declaration of error. I checked for duplicate files, but there are none. I tried to rename the files that didn’t work, and changed them back. It worked before, but now nothing. I posted a screenshot of the small snippet. I have more screenshots because I’m new to this forum, only allowed to post one. These are the only references I have. If this isn’t the correct section, please fix, im at a loss with this.

It looks like you have two structs named PrayersView. You need to rename or remove one. In general, posting code snippets is better than screenshots, because then we don’t have to OCR your screenshot to turn it into text.

1 Like

Thank you, new to this, most times I try to figure out the issues myself, but this really has me stuck. I can post code if you need me to

code 1:

struct PrayersView: View {

    enum Section: String, CaseIterable, Identifiable {

        case prayers = "Prayers", requests = "Requests"

        var id: String { rawValue }

    }



    @State private var selected: Section = .prayers

    @State private var selectedCategory: PrayerCategory? = nil



    @State private var prayers: [Prayer] = []

    @State private var requests: [PrayerRequest] = []



    @State private var showingAdd = false



    var body: some View {

        VStack(spacing: 12) {

            Text("Prayers")

                .font(.title2)

                .bold()

                .frame(maxWidth: .infinity, alignment: .leading)

            header

            categoriesBar

            content

        }

Code 2:

private struct PrayersView: View {

    var body: some View {

        NavigationStack {

            Text("Prayers go here")

                .padding()

                .navigationTitle("Prayers")

        }

    }

}

Code 3:

PrayersView()

                .tabItem {

                    Label("Prayers", systemImage: "hands.sparkles")

                }

Code 4:

#Preview {

    NavigationStack {

        PrayersView()

    }

}

Yes, you can't have two types named PrayersView at the same level in your project, even if one is private to the file it's declared in. It seems like you may want your first PrayersView to be PrayersScreen, since it seems to store all the state related to displaying Prayers and their requests, while the other view is simply showing a Prayer.

1 Like