Here is a simple swift script:
#!/usr/bin/env xcrun swift
import Foundation
let task = NSTask()
task.launchPath = \"/bin/echo\"
task.arguments = [\"farg1\", \"
If you unset the SDKROOT
environment variable before calling the swift script, it will then use the OS X sdk.
When building for iOS the implicit SDK for xcrun is the iOS SDK, so you have the change it to the Mac OS X SDK with a command line parameter. Change the first line in your script to:
#!/usr/bin/env xcrun --sdk macosx swift
+1 for @Mats's answer.
For anyone who get an error like *** is only available on OS X 10.11 or newer
.
You can:
#!/usr/bin/env xcrun --sdk macosx swift -target x86_64-macosx10.11
UPDATE 1:
If you don't get ready for Swift 3, but you are using Xcode 8, you can also control toolchain version:
xcrun --toolchain com.apple.dt.toolchain.Swift_2_3 -f swift
So:
#!/usr/bin/env xcrun --toolchain com.apple.dt.toolchain.Swift_2_3 --sdk macosx swift -target x86_64-macosx10.11
also checkout answers here: https://stackoverflow.com/a/36254848/1298043