Help! Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols

import SwiftUI

struct ContentView: View {
private var symbols = [“food1”, “food2”, “food3”]
@State private var numbers = [1, 2, 0, 3]
@State private var credits = 1000
private var betAmount = 5

        var body: some View {
            ZStack {
                var debug: some View {
                    MyViewWithError(property: self.property)
                }
           
                       //Background:
                       Circle()
                           .foregroundColor(Color (red: 90/255, green: 200/255, blue: 250/255))
                           .edgesIgnoringSafeArea(.all)
                       
                       Circle()
                           .foregroundColor(Color (red: 250/255, green: 45/255, blue: 85/255))
                           .rotationEffect(Angle(degrees: 45))
                           .edgesIgnoringSafeArea(.all)
                        .shadow(radius: 10)
                        .overlay(Circle().stroke(Color.yellow, lineWidth: 5))

                
                VStack {
                    Spacer()
                    
                    //Title:
                    HStack {
                        Image(systemName: "sun.min")
                            .foregroundColor(.black)
                        
                        Text("Eatable Turbine")
                            .bold()
                            .foregroundColor(.white)
                        
                        Image(systemName: "sun.min")
                        .foregroundColor(.black)
                    }.scaleEffect(2)
                    
                   
                    
                    Spacer()
                    //cards
                    HStack {
                        
                        Spacer()
                        
                        Image(symbols[numbers[0]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(10)

                        Image(symbols[numbers[1]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(10)
                        
                        Image(symbols[numbers[2]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(10)
                        
                        Image(symbols[numbers[3]])
                                                       .resizable()
                            .aspectRatio(0.5, contentMode: .fit)
                                                       .background(Color.white.opacity(0.5))
                                                       .cornerRadius(20)
                        
                     
                        Image()
                            .frame(width: 32.0, height: 32.0)
                        
                    
                        Spacer()
                        
                    }
                    
                    Spacer()
                //Button
                    Button(action: {
                        
                        //Change the images
                        
                        
                        self.numbers[0] = Int.random(in:
                            0...self.symbols.count - 1)
                        
                        self.numbers[1] = Int.random(in:
                            0...self.symbols.count - 1)

                        
                        self.numbers[2] = Int.random(in:
                            0...self.symbols.count - 1)
                        
                        //Check winnings
                        if self.numbers[0]
                            == self.numbers[1] && self.numbers[1] == self.numbers[2]{
                        
                        }
                        
                    })  {
                        Text("Spin")
                        .bold()
                            .foregroundColor(.white)
                            .padding(.all, 10)
                            .padding([.leading, .trailing], 30)
                            .background(Color.blue)
                            .cornerRadius(20)
                        
            }
            Spacer()
                    
                    
                    
        }
    }
}

}

The mistake is towards the front, where it is shown to me. I have no idea how to solve it! :frowning: please help me!!! Thanks! (I added the var debug, to make my life simpler of finding the easier words of the bug, I tried deleting it, but another bug came up!) Thanks!

You need to take out this, because you can’t declare a variable within the body property:

                var debug: some View {
                    MyViewWithError(property: self.property)
                }

This line will crash your app:

                    Image(symbols[numbers[3]])

Because numbers[3] is 3 but symbols[3] doesn’t exist, thus giving you a fatal index out of range error.

And you need to add a parameter here to tell SwiftUI what image you want to display:

                    Image()
                            .frame(width: 32.0, height: 32.0)

And a final note: You should enclose your code within backticks ``` on the line before and the line after the block in order to format it properly. It helps with readability and also when other posters try to copy and paste your code to test out solutions and such. For instance, this line caused errors when I pasted into Xcode:

private var symbols = [“food1”, “food2”, “food3”]

Why, because since it wasn’t included in a code block, the forum software converted the quotes into unicode “smart” or “curly” quotes, which Xcode doesn’t like. You can see the difference:

private var symbols = ["food1", "food2", "food3"]

Hi, thanks! But, when I follow what you are saying, I come up with this bug: Unable to infer complex closure return type; add explicit type to disambiguate. (I added the var debug to make the bug more explicit.) Thanks!

Thanks! (I fixed the curly brackets, but it just isn’t showing) Here’s the re-adjusted code:

import SwiftUI

struct ContentView: View {
private var symbols = [“food1”, “food2”, “food3”]
@State private var numbers = [1, 2, 0]
@State private var credits = 1000
private var betAmount = 5

        var body: some View {
           
           ZStack {
              
           
                       //Background:
                       Circle()
                           .foregroundColor(Color (red: 90/255, green: 200/255, blue: 250/255))
                           .edgesIgnoringSafeArea(.all)
                       
                       Circle()
                           .foregroundColor(Color (red: 250/255, green: 45/255, blue: 85/255))
                           .rotationEffect(Angle(degrees: 45))
                           .edgesIgnoringSafeArea(.all)
                        .shadow(radius: 10)
                        .overlay(Circle().stroke(Color.yellow, lineWidth: 5))

                
                VStack {
                    Spacer()
                    
                    //Title:
                    HStack {
                        Image(systemName: "sun.min")
                            .foregroundColor(.black)
                        
                        Text("Eatable Turbine")
                            .bold()
                            .foregroundColor(.white)
                        
                        Image(systemName: "sun.min")
                        .foregroundColor(.black)
                    }.scaleEffect(2)
           
                    
                    Spacer()
                    //cards
                    HStack {
                        
                        Spacer()
                        
                        Image(symbols[numbers[0]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(10)
                        
                        Image()
                                .frame(width: 32.0, height: 32.0)


                        Image(symbols[numbers[1]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(10)
                        Image()
                                .frame(width: 32.0, height: 32.0)

                        
                        Image(symbols[numbers[2]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(10)
                        
                       Image()
                       .frame(width: 32.0, height: 32.0)
                        
                    
                        Spacer()
                        
                    }
                    
                    Spacer()
                //Button
                    Button(action: {
                        
                        //Change the images
                        
                        
                        self.numbers[0] = Int.random(in:
                            0...self.symbols.count - 1)
                        
                        self.numbers[1] = Int.random(in:
                            0...self.symbols.count - 1)

                        
                        self.numbers[2] = Int.random(in:
                            0...self.symbols.count - 1)
                        
                        //Check winnings
                        if self.numbers[0]
                            == self.numbers[1] && self.numbers[1] == self.numbers[2]{
                        
                        }
                        
                    })  {
                        Text("Spin")
                        .bold()
                            .foregroundColor(.white)
                            .padding(.all, 10)
                            .padding([.leading, .trailing], 30)
                            .background(Color.blue)
                            .cornerRadius(20)
                        
            }
            Spacer()
                    
                    
                    
        }
    }
}

}

You still have several places (I count 3) where you don’t supply a parameter to Image. How is the compiler supposed to know what image to display?

                   Image()

OMG! You are a life-saver!!! It worked!!!