Xcode RealityKit / Failed to produce diagnostic for expression

553 views Asked by At

Im trying to make Augmented Reality app with RealityKit but ContentView.swift I have some problems What is missing here ?` You can see errors on picture which I shared. I followed some tutorial so Im new on Xcode and Realitykit.

Failed to produce diagnostic for expression; please file a bug report
Cannot find 'PlacementButtonsView' in scope

ERRORS Pic.

import SwiftUI
import RealityKit

struct ContentView : View {
    var models: [String] = {
        
        let filemanager = FileManager.default
        
        guard let path = Bundle.main.resourcePath, let files = try?
            filemanager.contentsOfDirectory(atPath:path) else
                { return[]
            }
        var avaliableModels: [String] = []
        for filename in files where filename.hasSuffix("usdz") {
            let modelName = filename.replacingOccurrences(of: ".usdz", with: "")
            avaliableModels.append(modelName)
        }
        
        return avaliableModels
    }()
    
    var body: some View {
        ZStack(alignment: .bottom) {
            ARViewContainer()
            
            ModelPickerView(models: self.models)
            
            PlacementButtonsView()
        }
    }
}

struct ARViewContainer: UIViewRepresentable {
    
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        
        return arView
        
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {}
    
}

struct ModelPickerView: View {
    var models: [String]
    
    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack(spacing: 20) {
                ForEach(0 ..<
                    self.models.count) { index in
                    Button(action: {
                        print("DEBUG: selected model with name: \(self.models[index])")
                    }) {
                        Image(uiImage: UIImage(named: self.models[index])!)
                            .resizable()
                            .frame(height: 60)
                            .aspectRatio(1/1,contentMode: .fit)
                            .background(Color.white)
                            .cornerRadius(12)

                         }
                             .buttonStyle (PlainButtonStyle())
                    
                      }
             }
       }
        .padding(15)
        .background(Color.black.opacity(0.5))
}

struct PlacementButtonsView: View {
    var body: some View {
        HStack {
            //Cancel Button
            Button(action: {
                print("DEBUG: model placement canceled.")
            }) {
                Image(systemName: "xmark")
                .frame(width: 60, height: 60)
                .font(.title)
                .background(Color.white.opacity(0.75))
                .cornerRadius(30)
                .padding(20)
                
            }
            
            //Confirm Button
            Button(action: {
                print("DEBUG: model placement confirmed.")
            }) {
                Image(systemName: "checkmark")
                .frame(width: 60, height: 60)
                .font(.title)
                .background(Color.white.opacity(0.65))
                .cornerRadius(30)
                .padding(20)
                
            }
        }
    }
}
    
#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

    
}
1

There are 1 answers

0
AudioBubble On

Check your braces. The PlacementButtonsView struct is actually nested within the ModelPickerView struct, and not globally available, hence why it is not available from your ContentView.

By the way, in Xcode, you can find this out by option clicking on the declaration of PlacementButtonsView:

Quick Help for PlacementButtonsView

ModelPickerView.PlacementButtonsView shows you what went wrong here; PlacementButtonsView is nested within ModelPickerView. This is why you seem to have a strange closing brace on the final line of your code sample - the same issue occurs with the preview, as it is also nested in ModelPickerView.

To make this issue more visible, and see similar issues like this in the future more easily, you can also have Xcode indent your code for you by selecting all (Cmd + A) and then pressing Control + I. You'll see the PlacementButtonsView struct indent, making it more clear that it is not globally available.