canImport only supports checking for top-level module availability while many have submodules with different availability. For example, while
CIFilter was introduced in iOS 5,
CIFilterBuiltins is only available on iOS 13+. Therefore, one might want to write code like this:
#if canImport(CoreImage.CIFilterBuiltins) ^ Unexpected platform condition argument: expected identifier import CoreImage.CIFilterBuiltins ... #endif
See also canImport(os.signpost)
Proposal? Bug fix?
#if canImport(module-name)tests for module support by name.
The question of "is this a proposal or a bug fix" comes down to the interpretation of "module name". Here are some facts:
- The original review / discussion never mentioned anything about submodules
The Swift Programming Language reference specifies that
module-name → identifier(likely based on the original implementation), but extending
canImportto check for submodules means the syntax will need to be updated to
module-name → import-path.
Do you all think this is just a simple bug fix, or is this something that has go through Swift evolution?