Why is SwiftUi always available in Swift Package without needing to declare dependency on it?

It feels strange to me that SwiftUi is always available to be imported to a file in Swift packages given that it's not part of Swift, but a library built on top of it. Shouldn't it need to be declared as a dependency too in the manifest file?

No, SwiftUI shouldn't be declared in the manifest file.

Unlike Swift packages, which are built on your machine (omitting binary targets), SwiftUI is a framework that ships with any modern Apple OS distribution. Your app links against it dynamically on application start.

But what if my package doesn't have any use for swiftui?

It's available because it's in the macOS/iOS/etc SDKs. Everything in there is available. There's no cost if you don't import it.

1 Like

(It's also pretty close to zero-cost if you do import it, due to how the dyld shared cache works, which is neat)

3 Likes