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
[email protected] | @SlaunchaMan <https://twitter.com/SlaunchaMan> |
jeffkelley.org <http://jeffkelley.org/>
> On Mar 23, 2016, at 9:27 PM, Dany St-Amant via swift-evolution
> <[email protected]> wrote:
>
>
>> Le 22 mars 2016 à 18:14, Erica Sadun via swift-evolution
>> <[email protected] <mailto:[email protected]>> 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
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution