[swift-evolution] [Draft] Adding a Build Configuration Import Test
Jeff Kelley
slaunchaman at gmail.com
Mon Mar 28 23:37:17 CDT 2016
This might be crazy, but we could also reuse try here:
import Foundation
try import UIKit {
// UIKit Code
}
else try import Cocoa
// Cocoa Code
}
This would attempt to import UIKit and if it succeeded, run the code in the closure.
Jeff Kelley
SlaunchaMan at gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> | jeffkelley.org <http://jeffkelley.org/>
> On Mar 23, 2016, at 9:27 PM, Dany St-Amant via swift-evolution <swift-evolution at swift.org> wrote:
>
>
>> Le 22 mars 2016 à 18:14, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> a écrit :
>>
>> <https://gist.github.com/erica/b7f4226b8201945602f2#motivation>Motivation
>>
>> Swift's existing set of build configurations specify platform differences, not module commonalities. For example, UIKit enables you to write view code supported on both iOS and tvOS. SpriteKit allows common code to render on OS X, iOS, and tvOS that would require an alternate UI on Linux. Testing for Metal support or Media Player would guard code that will not function on the simulator. If the simulator adopted these modules at some future time, the code would naturally expand to provide compatible execution without source modification.
>>
>> #if canImport(UIKit)
>> // UIKit-based code
>> #elseif canImport(Cocoa)
>> // OSX code
>> #elseif
>> // Workaround/text, whatever
>> #endif
> Not sure if its because I mainly live in a world of multi-architectures C cross-compiling, but for example if you canInclude some powerpc header, it does’t mean that your are compiling for powerpc. So, IMO, I think that #if didImport(Cocoa) would be a better wording. This effectively prevent one from doing:
>
> #if didImport(Cocoa)
> import Cocoa // Pointless, won’t work
> #endif
>
> So for conditionally import, we would still be forced to use some form of #if os(OSX)
>
> Dany
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160329/7bff677e/attachment.html>
More information about the swift-evolution
mailing list