Swiftui Canvas Won't Build

SwiftUI Canvas won't build

Finally figured it out!

So it turns out, the reason it couldn't find the library was because I was referencing it with a relative path to a spot outside of my project directory.

My build settings had the Framework Search Paths set up like this:

../path/to/my/framework

And when I normally built my project this worked fine and it would find the framework. So it seems as though by default my build script is run from my project directory.

When I tried to build for SwiftUI, it must have been doing so from outside my root project directory so the relative framework path so no longer correct and I got the error shown in the question.

Updating the framework search path to a (slightly less relative?) path like this:

$(PROJECT_DIR)/../path/to/my/framework

made it so the framework could be found. Now I can successfully build the project and my SwiftUI canvas updates as it should.

Xcode Canvas for SwiftUI previews does not show up

You need to be on Catalina macOS version (10.15), as stated in official tutorial

Be warned: Catalina doesn't support 32-bit applications, some old apps will stop working after update.

Can't preview SwiftUI Canvas with RealityKit scene

You have to fix several issues:

  1. You can't use anchoring component in iOS Simulator or in SwiftUI Canvas Preview, because it can only be used for pinning a virtual content to the real world surfaces. So no simulator for AR apps.

RealityKit Anchors are useless in iOS Simulator mode and SwiftUI Canvas Preview mode.

// Use it only for compiled AR app, not simulated...

let _: AnchoringComponent.Target.Alignment = .horizontal

Not only anchors are useless in iOS Simulator Mode and SwiftUI Preview Mode but also other session-oriented properties (including ARView.session) like ones you can see on a picture:

Sample Image


  1. Change .backgroundColor in ARView to any other desirable one. Default color sometimes doesn't allow you to see a RealityKit scene. Looks like a bug.
func makeUIView(context: Context) -> ARView {

let arView = ARView(frame: .zero)
let boxAnchor = try! Experience.loadBox()
boxAnchor.steelBox?.scale = SIMD3(5, 5, 5)
boxAnchor.steelBox?.orientation = simd_quatf(angle: Float.pi/4, axis: SIMD3(1,1,0))

arView.backgroundColor = .orange

arView.scene.anchors.append(boxAnchor)
return arView
}

And here's what you can see in SwiftUI Preview Area now:

Sample Image


  1. And, of course, you have to give a Camera Permission before using AR app. And it doesn't matter what you're using: Storyboard or SwiftUI.

You need to add Camera Usage Description property and arkit string in info.plist file:

Sample Image

XML version looks like this:

/*  info.plist

<key>NSCameraUsageDescription</key>
<string>Camera access for AR experience</string>

<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>arkit</string>
</array>

*/

After fixing these issues app compiles and works as expected (without any errors):

Sample Image



Related Topics



Leave a reply



Submit