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:
- 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:
- 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:
- 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:
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):
Related Topics
Extending a Delegate from a Base Class
iOS Sharecontext Tapping on Suggestion Intent Property of Extensioncontext Is Nil
Swift Function That Takes in Array Giving Error: '@Lvalue $T24' Is Not Identical to 'Cgfloat'
Swift Converting Signed Array of Int [Int8] to Unsigned Array of Int [Uint8]
Swiftui Animation and Subsequent Reverse Animation to Original State
Why Obj-C Instance Have 1 Retain Count Just Created
Cgaffinetransformmakerotation with Negative M_Pi
Swiftui - Scrollviewreader's Scrollto Does Not Scroll
How to Set the Size of an Uiviewrepresentable
Swiftui Card Flip Animation with Two Views, One of Which Is Embedded Within a Stack
iOS Do Scheduled Operation in Background or When App Active
Can't Dismiss Navigation Controller in Swift
Get "No Keychain Available" Error When Try to Access Keychain from App Extension