GoZoner GoZoner - 2 years ago 104
Swift Question

Swift Standard Library w/ Extra Symbols

A file with the following contents:

public class Foo {
var x : Int = 0
var y : Unit?

when compiled as part of a 'MacOS Framework' succeeds (in Xcode 8 beta). Notice that there is no
statement; I would expect the symbol
to be unbound - but apparently it is being found from the latest MacOS 'foundation'.

How do I ensure that the file is compiled w/o the

Note: if I compile from the command line with
swift File.swift
then, in fact,
is unbound, as desired:

File.swift:12:11: error: use of undeclared type 'Unit'
var y : Unit?

and, if I compile with the Swift Package Manager then Foundation is not implicitly imported.

So, how is Xcode inserting in implicit
that I don't need?

Answer Source

When building a framework, Xcode create a header file of TheFramework.h which includes contents like:

#import <Cocoa/Cocoa.h>

//! Project version number for SBFrames.
FOUNDATION_EXPORT double TheFrameworkVersionNumber;

//! Project version string for SBFrames.
FOUNDATION_EXPORT const unsigned char TheFrameworkVersionString[];

the inclusion of Cocoa.h imports Foundation. To avoid including Foundation edit TheFramework.h to be empty.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download