Why is my #available ignored by the compiler? (Xcode 15.4)

Hi, I have a workspace with a couple of modules, and now I'm making a Swift package. It's great.

However, i have this SwiftUI View extension you can see at the end of this post. My Swift package needs to have the target set to IOS16, so i have added #available where I need, like I've done in the past.

When i had this extension in my Widget extension target, it worked fine. However, i am now trying to move that into my new Swift package, with the Swift package declaration you can also find below.

When moved, i get an error from the compiler:

Type 'ContainerBackgroundPlacement' has no member 'widget'

It seems that my #available is ignored? I'm at a loss as to why this happens, so if anyone has any ideas i'm all ears. Otherwise guess i'll have to move it back to the Widget extension target :(

My extension code:

extension View {

    func widgetBackground(_ color: Color) -> some View {
        if #available(iOSApplicationExtension 17.0, *), #available(iOS 17.0, *) {
            return  containerBackground(color, for: .widget)
        } else {
            return background(color)
        }
    }
    .....more stuff
}

Swift Package (i renamed and cropped some stuff for simplicity): import PackageDescription

let package = Package(
    name: "MyPackage",
    platforms: [
        .iOS(.v16)
    ],
    products: [
        .library(
            name: "MyPackage",
            targets: ["MyPackage"]
        )
    ],
    targets: [
        .target(
            name: "MyPackage"
        ),
        .testTarget(
            name: "MyPackageTests",
            dependencies: ["MyPackage"]
        )
    ]
)
Why is my #available ignored by the compiler? (Xcode 15.4)
 
 
Q