Xcode 8 - Avoid Implicit Import of 'Foundation'

New to the Xcode 8 distribution is a module named 'NSUnit' which gets imported into Swift as 'Unit'. This is unfortunate for me as I already have a class named 'Unit'. My Xcode project DOES NOT explicitly include 'Foundation' and yet 'Unit' is imported and produces a name conflict.


How do I configure my Xcode project to avoid the implicit import of 'Foundation'?


For example, if I define Foo.swift to be:

class Foo {
 var bar : Unit?
}


then I WANT the compilation to fail. If I use Foo.swift in a new Xcode-defined Framework, then it INCORRECTLY compiles. If I compile, from the command line, then 'swift Foo.swift' fails (as expected); if I define a package.swift file and compile with 'swift build' then compilation fails (as expected). So, I don't want Foundation implicitly imported.

Anybody?


To reproduce, in Xcode create a MacOS or iOS Framework project, add the Foo.swift provided above, compile. Compilation will succeed; it shouldn't.

In their release notes, Apple states that you really need to be using 3 letter prefixes so as not to have namespace collisions with their code. So You need to add a 3 letter prefix.

What, then, explains the inconsistency in Apple's own tools - regarding compilation: Xcode != Swift Compiler; Xcode != Swift Package Manager?

I don't see the behavior you describe. I created a new macOS app, created a new source file, removed the template-provided "import Foundation" at the top of the file, added the above code, and I got a compilation error ("Use of undeclared type Unit").


If I add the code to one of the template-provided source files (AppDelegate.swift or ViewController.swift), then there's no error because those files import Cocoa, which imports Foundation indirectly. (Well, there's an error if the deployment target is earlier than 10.12, but that's unrelated to your problem.)


alex_kac: In their release notes, Apple states that you really need to be using 3 letter prefixes…


The current release notes? Can you give a reference for this? I've never seen anything in the Swiftiverse that suggested Apple is still pushing prefixes. In theory, module namespacing should make this unnecessary (although there's always the possibility of clashes in the module names themselves).

Thanks. It is an issue when creating a Framework with macOS 10.12

Xcode 8 - Avoid Implicit Import of 'Foundation'
 
 
Q