Hacker News new | comments | show | ask | jobs | submit login

I don't quite understand why they are putting specifics like detecting the iOS simulator in the core language.

They want functionality that is similar to the C preprocessor’s #if, but different in that they want to require both branches to syntax check.

They also want to locally evaluate the equivalent of such #if expressions (in contrast, in C, #if X requires preprocessing the file. That can mean reading dozens of header files, and is dependent on compiler flags)

I think this is a pragmatic way to accomplish that. It restricts you to conditions that Apple has deemed useful, but makes it easier to write good tooling.

Probably because "how do I detect simulator" is one of the most asked questions about swift. So Apple uses the leverage they have over the language.

I hope though that the way the targetEnvironment condition is implemented is that the 'simulator' exists only in the iOS library.

Because in the context of conditional compilation it is just yet another target.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact