<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"></span></font></div></div><blockquote type="cite"><div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">Gwendal Roué wrote:<br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div></div><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">`#if import Foo` can not deal with the fact that a single source file may have to perform the importability test several times.</span></font></div></blockquote><br></div><div id="AppleMailSignature">This would be less of a problem if conditional imports like that worked locally in all scopes of code, so you could write just</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"> func foo() {</div><div id="AppleMailSignature"> #if import UIKit</div><div id="AppleMailSignature"> // Actually use UIKit...</div><div id="AppleMailSignature"> #endif</div><div id="AppleMailSignature"> // UIKit no longer visible.</div><div id="AppleMailSignature"> }</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">— Pyry</div><div><br>For example:</div><blockquote type="cite"><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>#if canImport(UIKit)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>import UIKit</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>// Some UIKit-related declarations</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>#endif</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// Later in the same file</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func f() {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>#if canImport(UIKit)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>// Use UIKit-only declarations</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>#endif</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">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?</div><div class=""><br class=""></div><div class="">Still, testing for module importability is not the same as importing it.</div></blockquote></body></html>