# How to exclude RealityKitContent from Swift package for iOS

**URL:** <https://forums.swift.org/t/how-to-exclude-realitykitcontent-from-swift-package-for-ios/72029>\
**Category:** Package Manager\
**Tags:** ios, visions\
**Created:** [May 23, 2024, 1:00pm UTC](https://forums.swift.org/t/how-to-exclude-realitykitcontent-from-swift-package-for-ios/72029 "2024-05-23T13:00:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![waldgeist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/waldgeist/32/35534_2.png) [@waldgeist](https://forums.swift.org/u/waldgeist)\
**Post date:** [May 23, 2024, 1:00pm UTC](https://forums.swift.org/t/how-to-exclude-realitykitcontent-from-swift-package-for-ios/72029/1 "2024-05-23T13:00:28Z")

</div>

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.

So I am trying my luck with the real guys instead 🙂

Here's my Package.swift file:

```swift
// 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"]),
    ]
)

```

---

<div class="post-metadata">

**Author:** ![Lancelotbronner](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lancelotbronner/32/22071_2.png) [@Lancelotbronner](https://forums.swift.org/u/Lancelotbronner)\
**Post date:** [May 23, 2024, 4:05pm UTC](https://forums.swift.org/t/how-to-exclude-realitykitcontent-from-swift-package-for-ios/72029/2 "2024-05-23T16:05:44Z")

</div>

I don't really see what's complicated about the Apple docs?

> **[product(name:package:condition:) | Apple Developer Documentation](https://developer.apple.com/documentation/packagedescription/target/dependency/product(name:package:condition:))**
>
> Creates a target dependency on a product from a package dependency.

Off the top of my head:

```swift
.target(
    name: "Overlays",
    dependencies: [
        "BackendServices", "MeteorDDP",
        .product(name: "OverlaysRealityKitContent", condition: .when(platforms: [.visionOS]))
    ]
),

```

---

<div class="post-metadata">

**Author:** ![waldgeist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/waldgeist/32/35534_2.png) [@waldgeist](https://forums.swift.org/u/waldgeist)\
**Post date:** [May 23, 2024, 5:12pm UTC](https://forums.swift.org/t/how-to-exclude-realitykitcontent-from-swift-package-for-ios/72029/3 "2024-05-23T17:12:10Z")

</div>

Thanks. Unfortunately, it does not work. It expects an additional "package" string. I tried to set this to "OverlaysRealityKitContent", but this won't compile either.

As a side-note: Any combination I tried before where this was still included

```swift
dependencies: [
        ...
        .package(
            path: "Packages/OverlaysRealityKitContent"
        ),
    ],

```

lead to the error message

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

Not sure if patching the targets alone will fix this.

(Regarding the Apple docs in general: I really don't think they are comprehensible. Way too scarce, and almost always without concrete usage examples. I struggled with this a lot when I started learning Swift (and especially SwiftUI for visionOS). I have a decent development background as a full stack web dev with a lot of different frameworks, plus C# and Unity, and I think Apple's docs are by far the worst I've seen so far. Even worse than Unity's, actually.)

---

<div class="post-metadata">

**Author:** ![Lancelotbronner](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lancelotbronner/32/22071_2.png) [@Lancelotbronner](https://forums.swift.org/u/Lancelotbronner)\
**Post date:** [May 23, 2024, 5:30pm UTC](https://forums.swift.org/t/how-to-exclude-realitykitcontent-from-swift-package-for-ios/72029/4 "2024-05-23T17:30:14Z")

</div>

For the `package` argument, you can try explicitly specifying the package name of your dependency.

```swift
dependencies: [
    ...
    .package(
        name: "OverlaysRealityKitContent",
        path: "Packages/OverlaysRealityKitContent"),
]

```

I don't know of a way to prevent Xcode (or SwiftPM) from trying to compile an unused dependency. I haven't played with `realitytool` either so I don't think I can help you on that side.

As for Apple docs, I now understand what you meant and certainly agree! They're barely useful, usually sparse and lack pretty much all of the critical information one might need. Sorry I have a lot of frustration with them.. I usually need to check the Cocoa documentation archive (or `man` pages!).

---

<div class="post-metadata">

**Author:** ![waldgeist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/waldgeist/32/35534_2.png) [@waldgeist](https://forums.swift.org/u/waldgeist)\
**Post date:** [May 24, 2024, 7:15am UTC](https://forums.swift.org/t/how-to-exclude-realitykitcontent-from-swift-package-for-ios/72029/5 "2024-05-24T07:15:15Z")

</div>

Thanks, this resolves the package resolution, but I still get the error message about the `realitytool`.
