[swift-evolution] [Review] SE-0075: Adding a Build Configuration Import Test

Pyry Jahkola pyry.jahkola at iki.fi
Fri May 13 04:05:26 CDT 2016


> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160513/9b249247/attachment.html>


More information about the swift-evolution mailing list