[swift-evolution] Idea: Support #if os(Darwin) as shorthand for os(iOS) || os(OSX) || os(watchOS) || os(tvOS)
Evan Maloney
emaloney at gilt.com
Fri Feb 19 15:18:18 CST 2016
Adding in the different forms of compile-time conditionals our code uses in Objective-C, the following tests would be useful:
• Is the target an Apple platform (iOS, OS X, tvOS, watchOS) or not? (Answers the question "can I import Foundation"?)
• Is the target a "common UIKit platform" (compiles on both iOS and tvOS) or not? (Answers the question "can I import UIKit"?)
• Is the target a specific platform (iOS, OS X, tvOS, watchOS, Linux, etc.)?
• Is the target in Debug or Release mode?
• Is the target a simulator environment or a physical device?
• Is the target built for running tests?
All of our cases are covered by the questions above, but as Jordan indicates, other people may also need to know more about the processor architecture.
> On Feb 19, 2016, at 2:53 PM, Jordan Rose via swift-evolution <swift-evolution at swift.org> wrote:
>
> I agree that we need something here, but I really like the property we have today that all of the "os" options are mutually exclusive. (Compare: TARGET_OS_IPHONE and TARGET_OS_IOS in <TargetConditionals.h>.) I'd be happy to invent a new predicate for this, though.
>
> Other considerations:
> - Different Linux distros?
> - Common ground across BSDs?
> - Unixy? (vs. Windows)
>
> And for other platform conditions:
> - Architecture subtypes?
> - Architecture families? ("32-bit" is a good one.)
>
> Jordan
>
>
>> On Feb 19, 2016, at 11:19, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> I'd like to see #if support os(Darwin) as shorthand for any Apple platform. This is a lot shorter to type, and it's also future-compatible if Apple ever releases another Darwin-based platform. If os(Darwin) evaluates to true, then `import Darwin` should always work, and presumably `import Foundation` as well.
>>
>> Without this, I think people are going to be tempted to write `if !os(Linux)` instead of writing out all 4 Apple platforms, and this is unfortunate because it makes the assumption that Linux is the only non-Apple platform, and that's simply not true.
>>
>> -Kevin Ballard
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list