How should SupportedPlatform work?

I'm a bit confused about how is SupportedPlatform supposed to work.
If the package manifest defines that it supports only iOS, e.g GitHub - twitter/TwitterTextEditor: A standalone, flexible API that provides a full-featured rich text editor for iOS applications., why does Xcode still allow that package to be added to a macOS project? Or why does swift build try to build for macOS?
Is this not fully implemented or am I missing something?

platforms: [.iOS(.v11)] means roughly the same thing as @available(iOS 11, *). It declares that the package requires at least iOS 11, but is fully available on any other platform.

Do not consider the platforms parameter as an exhaustive list of the platforms a package supports. Such version limitations can only be declared for platforms that contain the standard library embedded in the operating system. For platforms where the standard library must be distributed with the product (statically or dynamically), version constraints would make no sense. You will never see Windows, the various Linux flavours, web assembly or Android in that list even for packages that expressly support them.

Many packages do not touch any platform‐specific details and will just work everywhere. The platforms list was deliberately designed to make it easier for new or exotic platforms to use a package, even if the package author has never heard of the platform. Thus there is no way of deliberately barring a package from compiling on a particular platform. (Should you discover a good reason to break that guideline, it is possible to combine #if with #error in a source file.)

If you want to communicate to clients which platforms are actively tested and known to be stable, that sort of information belongs in the package’s read‐me or documentation.

Officially, command‐line SwiftPM only—and always—supports building for the host platform. (Some experimental support does exist for cross‐compilation if you monkey around with building Swift from source to get the pieces you need).

Terms of Service

Privacy Policy

Cookie Policy