Swift: How to compile your Swift code

You can compile your command line interface Swift code like so:

$ xcrun swiftc -c fibonacci.swift  -F /System/Library/Frameworks -I/usr/include
$ xcrun swiftc -o fibonacci fibonacci.o

 

If you also have regular C code, you can do it like the following:

1. Compile regular .m file:

$ xcrun clang C.m -o C.o -c

Be sure to import the bridge header .h file

$ xcrun swiftc -c S.swift -import-objc-header C.h -F /System/Library/Frameworks -I/usr/include

 

 

What's the SDK path?

$ xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk

 

Helpful?

Swift: How to compile your Swift code

Leave a Reply

Your email address will not be published. Required fields are marked *