[swift-evolution] Proposal Idea : Library (third party) Importable Checking

Joe Groff jgroff at apple.com
Thu Jan 14 23:44:24 CST 2016


> On Jan 14, 2016, at 9:22 AM, Jo Albright via swift-evolution <swift-evolution at swift.org> wrote:
> 
> This is a thought from a current problem I am running into (and have ran into in the past).
> 
> If you want to write any code using a library, you must have that library imported into the file. Totally cool with this for most cases.
> 
> Situation :
> 
> Building a third party library that can be used by others to simplify working with server APIs. I want to give the developer an option to use another third party library within mine. However, I don’t want my library to depend on the other library.
> 
> Possible Solution :
> 
> Add a system that does two things. 1) Checks for a library and if found imports it into file. 2) Checks if library is imported and allows source kit to parse conditional scope.
> 
> @importable ThirdPartyLibrary // would check if library is added to project and import it
> 
> if #imported(ThirdPartyLibrary) {
>     
>     // would check if library is imported before source kit parses scope
>     
>     // if library is not imported
>     // scope would remain unparsed
>     // scope could be removed as if it were a comment
>     
> }
> 
> Thanks.

Interesting idea. Unless I'm misunderstanding something, it seems to me you could kill both birds with one stone. If we add an 'importable' predicate to the '#if' language, then you can already use that to conditionalize the import:

#if importable(ThirdPartyLibrary)
import ThirdPartyLibrary
/* decls that depend on library */
#endif

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160114/452efa97/attachment.html>


More information about the swift-evolution mailing list