#import (project scope import) (former: "Pre-imported modules (sort of PCH)”)


(Vanderlei Martinelli) #1

On second thought in the proposal: maybe bringing `#import` to the party as
a project scope `import` instead of having a dedicated file is a better
ideia.

Something like:

#import MyAwsomeFramework

The difference between `#import` and the regular `import`: the `#import`
says “import this module everywhere for then entire project even if it was
imported again somewhere” and the `import` says "import this module only
for this file".

The `#import` would be included in any source code file and taken into
account. I know the analyser/compiler have to search each single file for
`global imports`, but they already do something like this when we use
`public let something = “something”` outside a structure/class.

What do you think?

Best,
-Van

···

On Tue, Jan 26, 2016 at 12:19 AM, Vanderlei Martinelli via swift-evolution < swift-evolution@swift.org> wrote:

Hello everybody.

I've been following the list, but I have not had time to participate more
actively. I must say that I am very happy for what has been discussed, the
more because of what Swift will *not* become than of what it will become.
:wink:

OK. In Objective-C and other languages we have “.PCH” files or some kind
of “prefix headers”. In Swift we do not have header files (thankfully), but
there is no simple way to “pre-import” modules in a way that all source
files can “see” them without the need of a big list of “imports” at the
beginning of each file, every single time. I know that the “.PCH-like” it
is not a good practice in most cases, but I believe it would be interesting
in some other cases.

Today we have some kind of this functionality when using bridging headers,
but this is in fact a side effect provided by the interoperability with
Objective-C. I am suggesting a pure Swift version of this functionality.

I do not know how we can implement this in Swift, but since we now have
the special case of “Package.swift” to handling SPM things, maybe something
like “Preimport.swift” or “Modules.swift” or something better than these
names (I do not like them…) with the intention of saying: “Hi, compiler!
I'm listing here the modules that are common to the whole project, OK? Can
you take them into account when compiling each project source code file
from now?"

What do you think?

Regards,

Vanderlei Martinelli

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution