> Gwendal Roué wrote: > > `#if import Foo` can not deal with the fact that a single source file may > have to perform the importability test several times.
This would be less of a problem if conditional imports like that worked locally in all scopes of code, so you could write just func foo() { #if import UIKit // Actually use UIKit... #endif // UIKit no longer visible. } — Pyry > For example: > > #if canImport(UIKit) > import UIKit > // Some UIKit-related declarations > #endif > // Later in the same file > func f() { > #if canImport(UIKit) > // Use UIKit-only declarations > #endif > } > > I know, I know, some will tell me to refactor my code. So let's just say I'm > prototyping and that the code doesn't have its final shape, OK? > > Still, testing for module importability is not the same as importing it.
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution