Xcode Gm: No Swift Language for Os X Command Line Tool Project

Xcode GM: no swift language for OS X command line tool project?

Xcode 6 GM is for iOS Swift development. Xcode 6.1 Beta is for OS X / iOS Swift development.

Release Notes

How can I use swift in Terminal?

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

then you can do one of these:

xcrun swift 
lldb --repl

As of Xcode 6.1 - typing swift in the terminal launches the REPL as well.

Swift Command Line Tool utilizing Process() and multithreading crashes after a certain number of execution rounds (~3148)

I have found a fix while researching this bug. It seems that, despite what the documentation claims, Pipe will not automatically close its reading filehandle.

So if you add a try outputPipe.fileHandleForReading.close() after reading from it, that will fix the issue.

Can't add dynamic frameworks to Command Line Tool

Command-line tools are best with static archives because everything is distributed as a single binary. Looking at Realm, I don't see that there is a static archive option. They do have an iOS static framework that I got compiling for macOS but that's not quite what you want. You might want to try playing with Realm's source a bit more to see if you can get it to produce a static archive.

In the mean time, as a workaround, you'll need to tell Xcode where to find the dylibs at runtime and also to install them somewhere.

  1. In your Build Settings, go down to "Runpath Search Paths" and add "@rpath".
  2. In Build Phases, under Copy Files, click the + button and add both Realm.framework and RealmSwift.framework from your project.
  3. Because Realm is compiled with an older version of Swift, you also need to specify "Use Legacy Swift Language Version" in Build Settings.

That will get your project building and finding the Realm libraries but now it will fail to find libswiftCore.dylib. That's because normally command-line tools are statically linked with the Swift library but as soon as you add a framework/dylib, the linker no longer includes the static version.


  1. Go back to Build Phases, Copy Files, and add the following:
libswiftObjectiveC.dylib
libswiftIOKit.dylib
libswiftFoundation.dylib
libswiftDispatch.dylib
libswiftDarwin.dylib
libswiftCoreGraphics.dylib
libswiftCore.dylib

You can find them inside your Xcode installation and then ./Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/lib/swift/macosx/

WARNING: Keep in mind that you will need to distribute the frameworks and the dylibs with your command-line tool and they will need to be in the same directory as the tool. You can put them somewhere else on the system by specifying a different runpath but you'll still need them distributed with your tool.

The nice thing about a .app bundle is that it gives you a place to put this stuff and users can just drag-and-drop it to install it. If you could get a static archive version of Realm, you could distribute everything in one binary.

Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler

OK, Turns out if you watch the WWDC video, they explain it:
https://developer.apple.com/videos/play/wwdc2019/416/

You need to set the Build Settings > Build Options > Build Libraries for Distribution option to Yes in your framework's build settings, otherwise the swift compiler doesn't generate the neccessary .swiftinterface files which are the key to future compilers being able to load your old library.

This ends up in your project.pbxproj file as:

BUILD_LIBRARY_FOR_DISTRIBUTION = YES;

After setting this flag, a framework I compiled using Xcode 11.0 (swift 5.1) was able to be used by Xcode 11.2 (swift 5.1.2) and everything appears to be working correctly.

Hopefully this question/answer will serve as a useful reference for everyone who hasn't watched all the WWDC videos

If the error still persists go to Product > Clean Build Folder and Build again.

Module compiled with swift 3.0 cannot be imported in Swift 3.0.1

SwiftyJson is being downloaded precompiled by carthage. The precompiled download is with Swift Version 3.0. That makes the compiler complain that the version is not correct. Using the following command:

carthage update --platform iOS --no-use-binaries

SwiftyJson (and all other frameworks within Carthage) will be compiled locally using the local version of Swift (3.0.1) and the compiler will not complain anymore.

Invalid Swift Support / The SwiftSupport folder is empty

important note: this only works for projects that do not use swift, see comment below

I just met the same issue and resolved it by making the following change -
If you used to have Swift files in your project but then removed them, you only need to set "Embedded Content Contains Swift Code" to NO in Build Options.

Alamofire Xcode 8 Swift 3 results in 786 compile errors

Upgrading to the latest Cocoapods (at the time of this answer: version 1.1.0.beta.2) via the command:

gem install cocoapods --pre
seemed to solve the issue for my circumstance.



Related Topics



Leave a reply



Submit