How to exclude RealityKitContent from Swift package for iOS?

I've created an app for visionOS that uses a custom package that includes RealityKitContent as well (as a sub-package). I now want to turn this app into a multi-platform app that also supports iOS.

When I try to compile the app for this platform, I get this error message:

Building for 'iphoneos', but realitytool only supports [xros, xrsimulator]

Thus, I want to exclude the RealityKitContent from my package for iOS, but I don't really know how. The Apple docs are pretty complicated, and ChatGPT did only give me solutions that did not work at all.

I also tried to post this on the Swift forum, but no-one could help me there either - so I am trying my luck here.

Here is my Package.swift file:

// swift-tools-version: 5.10

import PackageDescription

let package = Package(
    name: "Overlays",
    platforms: [
        .iOS(.v17), .visionOS(.v1)
    ],
    products: [
        .library(
            name: "Overlays",
            targets: ["Overlays"]),
    ],
    dependencies: [
        .package(
            path: "../BackendServices"
        ),
        .package(
            path: "../MeteorDDP"
        ),
        .package(
            path: "Packages/OverlaysRealityKitContent"
        ),
    ],
    targets: [
        .target(
            name: "Overlays",
            dependencies: ["BackendServices", "MeteorDDP", "OverlaysRealityKitContent"]
        ),
        .testTarget(
            name: "OverlaysTests",
            dependencies: ["Overlays"]),
    ]
)

Based on a recommendation in the Swift forum, I also tried this:

    dependencies: [
         ...
        .package(
            name: "OverlaysRealityKitContent",
            path: "Packages/OverlaysRealityKitContent"
        ),
    ],
    targets: [
        .target(
            name: "Overlays",
            dependencies: [
                "BackendServices", "MeteorDDP",
                .product(name: "OverlaysRealityKitContent", package: "OverlaysRealityKitContent", condition: .when(platforms: [.visionOS]))
            ]
        ),
       ...
    ]

but this won't work either.

The problem seems to be that the package is listed under dependencies, which makes the realitytool kick in. Is there a way to avoid this? I definitely need the RealityKitContent package being part of the Overlay package, since the latter depends on the content (on visionOS). And I would not want to split the package up in two parts (one for iOS and one for visionOS), if possible.

Answered by DTS Engineer in 790352022

See "What's new" here. and note that:

"With RealityKit 4, you can build for iOS, iPadOS, macOS, and visionOS — all at once. RealityKit 4 aligns its rich feature set across iPhone, iPad, Mac and Apple Vision Pro. Reality Composer Pro, a new tool that launched with Apple Vision Pro, enables development of spatial apps on all these platforms. Shaders built with MaterialX, portals, particles, and many other features can now be used with RealityView on all four platforms. ..."

See "What's new" here. and note that:

"With RealityKit 4, you can build for iOS, iPadOS, macOS, and visionOS — all at once. RealityKit 4 aligns its rich feature set across iPhone, iPad, Mac and Apple Vision Pro. Reality Composer Pro, a new tool that launched with Apple Vision Pro, enables development of spatial apps on all these platforms. Shaders built with MaterialX, portals, particles, and many other features can now be used with RealityView on all four platforms. ..."

How to exclude RealityKitContent from Swift package for iOS?
 
 
Q