Q:

Apple framework not found when building Archive

I'm trying to add optional support for an AR feature to an existing app using RealityKit. The app builds and runs fine on both iOS 10 and iOS 13 devices with the optional feature only enabled in the latter.  However, when I build for a Generic iOS Device or try to Archive, I get an error No such module 'RealityKit' on any import RealityKit statement and the build fails.
The build target for the app is iOS 10, with RealityKit being available in iOS 13.  I've added guards to only build certain classes if @available( iOS 13.0, *) and weak-linked the RealityKit framework using a -weak_framework RealityKit Other Linker Flag in my Build Settings.
Same thing happens when I do a Release instead of a Debug build, but I couldn't find any difference in the scheme settings. I'm not using pods and the RealityKit is a standard Apple framework introduced in iOS 13.  
Any ideas how to get around this?

A:

Looks like the way around this issue is with a canImport(module) preprocessor directive.  This worked for me:
#if canImport(RealityKit)

import RealityKit

@available(iOS 13.0, *)
class MyARClass {

    @IBOutlet weak var arView: ARView!

...
}

#endif

