I only create a new property of RealityKit. Xcode won't be able to preview the SwiftUI canvas. But it can build successfully.
- I create the App by Xcode.
- Choose Augmented Reality App and set User Interface to SwiftUI.
- The project can work normally.
import SwiftUI
import RealityKit
struct ContentView : View {
var body: some View {
return VStack {
Text("123")
ARViewContainer().edgesIgnoringSafeArea(.all)
}
}
}
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
- I only create a new property of RealityKit in makeUIView function.
let test: AnchoringComponent.Target.Alignment = .horizontal
- The project cannot preview canvas and appear the error
'Alignment' is not a member type of 'AnchoringComponent.Target'
I am so confused what I met. Has anyone meet the same issue?