I read What's new in Xcode 6. The article introduces some new feature about Xcode 6, and it says:
Command Line
Xcode’s debugger includes an interactive version of the Swift language, known as the REPL (Read-Eval-Print-Loop). Use Swift syntax to evaluate and interact with your running app or write new code in a script-like environment. The REPL is available from within LLDB in Xcode’s console, or from Terminal.
I want to know how to get the REPL?
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.
Alternatively, if you don't want to mess up your current dev environment, you can just run:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
Step 1: Open Terminal
Step 2: Type "swift"
Step 3: There's no step 3
Example:
GoldCoast:~ macmark$ swift
Welcome to Swift! Type :help for assistance.
1> println("Hello, world")
Hello, world
2> var myVariable = 42
myVariable: Int = 42
3> myVariable = 50
4> let myConstant = 42
myConstant: Int = 42
5> println(myVariable)
50
6> let label = "The width is "
label: String = "The width is "
7> let width = 94
width: Int = 94
8> let widthLabel = label + String(width)
widthLabel: String = "The width is 94"
9> :exit
GoldCoast:~ macmark$
In Xcode 6.1.1 with Command Line Tools installed you can execute scripts by referencing directly to /usr/bin/swift the following way:
#!/usr/bin/swift
let variable: String = "string"
print("Test \(variable)")
In the same fashion as running Swift from the Terminal, you can also execute scripts.
Just use the following shebang, and run your script. (As per Chris Lattner, creator of Swift)
#!/usr/bin/env xcrun swift -i
If any one cares a simple Swift script shebang:
#!/usr/bin/env xcrun --sdk macosx swift
If specific target version is required
#!/usr/bin/env xcrun --sdk macosx swift -target x86_64-macosx10.11
If specific toolchain is required (like you want to use Swift 2.3 but you are using Xcode 8)
#!/usr/bin/env xcrun --toolchain com.apple.dt.toolchain.Swift_2_3 --sdk macosx swift -target x86_64-macosx10.11
If you want to use Swift 2.2 in your Xcode 7.3.1, let's assume Xcode 7.3.1 is located at /Applications/Xcode7.app
sudo xcode-select -s /Applications/Xcode7.app/
xcrun --sdk macosx swift
from now on the default active developer directory changed, you can check that using:
xcode-select -p
If you want to use snapshots provided by Swift.org, you should not miss Installation here.
as first answered by me in Run swift script from Xcode iOS project as build phase
** update as of xcode6 beta 4 **
this can also be done on xcode preferences. simply go to xcode -> preferences -> locations.
for command line tools simply select the version you want from drop down list options, refer picture below. (swift requires path to be xcode6's path).
I will leave my previous answer below as well.
what Kaan said and you can also use an apple script to make simple application so you can use it to switch back and forth.
open apple script > paste this below code & export it as an application so with just one click you can switch to default path or beta path (to use swift)
set xcode6Path to "xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer"
set xcodeDefaultPath to "xcode-select -switch /Applications/Xcode.app/Contents/Developer"
display dialog "set xcode sdk path to " buttons {"xcode 6", "default"} default button 1
copy result as list to {buttonPressed}
if buttonPressed is "default" then
try
do shell script xcodeDefaultPath with administrator privileges
end try
else
try
do shell script xcode6Path with administrator privileges
end try
end if
then run > xcrun swift
disclaimer
the script assumes you have both xcode6-beta & xcode5 installed.
if you're a new developer who's trying out only xcode6beta you will not need any script or setting path manually. simply run xcrun swift as the path is already set for you.
when xcode6 is finally released you will need to reset your path back to default from this simple app and never use it again.
After installing the official Xcode 6.1 release, there is a swift command in /usr/bin/swift.
Bear in mind that if you have a Python different from the Apple-supplied Python in the path, swift can fail with ImportError: No module named site. In that case, make sure that you do export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin before calling swift.
The xcrun command will use the DEVELOPER_DIR environment variable to override the currently selected Xcode installation (as set with xcode-select). You can use that to construct a single command that'll run swift on the command line and put you in the REPL. That looks like this:
/usr/bin/env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer xcrun swift
and you can alias that to just 'swift':
alias swift="/usr/bin/env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer xcrun swift"
As an interesting side note, you can use the same kind of invocation to run a swift script just like you'd use bash or python by adding a -i:
#!/usr/bin/env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer xcrun swift -i
println("Hello World!")
Of course, once Xcode 6 is released officially and you switch to that as your default developer tools, you can drop the DEVELOPER_DIR=.. bits and just use "xcrun swift".
make sure you install xcode 6.0 ,but not 6.1
If you get an error:
<unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift
just run
xcrun --sdk iphonesimulator8.0 swift
or you can
export SDKROOT="iphonesimulator8.0"
and then
xcrun swift
Use "xcodebuild -showsdks" to list the available SDK names.
if you install xcode 6.1,just
sudo xcode-select -s /Applications/*your-Xcode-6.1-path.app*/Contents/Developer
xcrun swift
For XCode6, run these commands:
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
$ xcrun swift
If you get an error:
<unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift
try:
xcrun swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
open Terminal,
$sudo xcode-select -switch /Applications/Xcode6-Beta6.app/Contents/Developer
Notice: The Xcode6-Beta6.app should be replaced to appropriate version you installed
Then put this line alias swift='xcrun swift' to ~/.bash_profile
And,
$source ~/.bash_profile
$swift
There you go!
With the help of Swift REPL(Read Eval Print Loop).
Developers familiar with interpreted languages will feel comfortable in this command-line environment, and even experienced developers will find a few unique features
Launch Terminal.app and type swift and press enter. You’ll then be in the Swift REPL.
1> print("Hello Swift REPL")
Hello Swift REPL
2> 10 + 20
$R0: Int = 30
3> var name = "Yogendra Singh"
name: String = "Yogendra Singh"
4> print(name)
Yogendra Singh
5>
This is the error:
sys/cdefs.h' file not found
what i've done is just follow the offical steps,the" gclient sync --force" prompt the following errors:
In file included from /Users/ted/Desktop/webrtcSrc/WD/trunk/third_party/llvm/projects/compiler-rt/lib/asan/asan_fake_stack.cc:14:
In file included from /Users/ted/Desktop/webrtcSrc/WD/trunk/third_party/llvm/projects/compiler-rt/lib/asan/asan_allocator.h:19:
In file included from /Users/ted/Desktop/webrtcSrc/WD/trunk/third_party/llvm/projects/compiler-rt/lib/asan/asan_interceptors.h:18:
/Users/ted/Desktop/webrtcSrc/WD/trunk/third_party/llvm/projects/compiler-rt/lib/interception/interception.h:90:10: fatal error: 'sys/cdefs.h' file not found
=====
what the problem?
On Mavericks? Try typing "xcode-select --install" to pop up the dialog to install the Xcode command-line tools. That should give you a /usr/include directory and then building LLVM should work.
Ref: http://clang-developers.42468.n3.nabble.com/Naive-Mavericks-Trunk-Build-Errors-td4035480.html
I just ran into this issue with my Xcode project:
whenever I run it, it says there is the following error GenerateDSYMFile /Users/obleopold/Library/Developer/Xcode/DerivedData/richhh-bzvkjxyolcsbhoffzrtzyohyzhye/Build/Products/Debug-iphoneos/richhh.app.dSYM /Users/obleopold/Library/Developer/Xcode/DerivedData/richhh-bzvkjxyolcsbhoffzrtzyohyzhye/Build/Products/Debug-iphoneos/richhh.app/richhh
cd /Users/obleopold/Documents/richhh
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/obleopold/Library/Developer/Xcode/DerivedData/richhh-bzvkjxyolcsbhoffzrtzyohyzhye/Build/Products/Debug-iphoneos/richhh.app/richhh -o /Users/obleopold/Library/Developer/Xcode/DerivedData/richhh-bzvkjxyolcsbhoffzrtzyohyzhye/Build/Products/Debug-iphoneos/richhh.app.dSYM
The main issue states:
error: unable to open executable ''
Here is some more info:
My project name is: richhh,
my computer username is: obleopold
If you need any more information, please comment.
Go to Product->Clean and then Product->Clean builds(option comes by pressing option button). Delete the derived data, restart Xcode and try running
I have a weird thing when I try to compile with xcodebuild.
If I open the project on the mac with XCode, the code compile without any warning.
If I use the following command line :
xcodebuild -configuration Debug -target myApp PROVISIONING_PROFILE=B5AD0E27-B224-4962-B0DC-XXXXXXXX
I have some compilation error :
/Users/myUser/.jenkins/jobs/myApp/workspace/prj/Controllers/DeclarerEtape1Adresse.m:75:6: error: receiver type 'DeclarerEtape1Adresse' for instance message does not declare a method with selector 'rechercheAdresse' [4]
[self rechercheAdresse];
^
1 error generated.
This errors can appear in external code (taken from github). It seems that the compilator is much strict in command line mode than with Xcode.
Is there any specific configuration in command line ?
Thank you for your feedback.
James, you're the boss :p I tried xcodebuild -version on both environment and the ci server used an old SDK 4.2.X. So I used the sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer and it fixes the issue
I am currently trying to streamline our build and release process with an automated build which runs on an OSX server machine , a MacMini running OSX 10.6.7 with xCode 4.0.1 and iOS SDK 4.3 installed (latest release from Apple).
I have followed Mike Nachbaur's excellent guide and it feels like I'm almost there but I still have one final obstacle to overcome.
So. We have our app which build fine on:
a) My laptop from within xCode
b) My laptop from command line with xcodebuild
c) the build machine from within xCode
BUT it does not work on
d) the build machine from the command line with xcodebuild.
Here is the end of the console output:
CreateUniversalBinary build/Distribution-iphoneos/CallControl.app/CallControl normal "armv6 armv7"
cd /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/Users/ainutveckling/Jenkins/tools/jdk6/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/usr/bin/lipo -create /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol/build/Callcontrol.build/Distribution-iphoneos/CallControl.build/Objects-normal/armv6/CallControl /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol/build/Callcontrol.build/Distribution-iphoneos/CallControl.build/Objects-normal/armv7/CallControl -output /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol/build/Distribution-iphoneos/CallControl.app/CallControl
GenerateDSYMFile build/Distribution-iphoneos/CallControl.app.dSYM build/Distribution-iphoneos/CallControl.app/CallControl
cd /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/Users/ainutveckling/Jenkins/tools/jdk6/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/usr/bin/dsymutil /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol/build/Distribution-iphoneos/CallControl.app/CallControl -o /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol/build/Distribution-iphoneos/CallControl.app.dSYM
ProcessProductPackaging "/Users/ainutveckling/Library/MobileDevice/Provisioning Profiles/F792F2E5-45DB-43C7-969C-6012C59BF778.mobileprovision" build/Distribution-iphoneos/CallControl.app/embedded.mobileprovision
cd /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/Users/ainutveckling/Jenkins/tools/jdk6/bin:/usr/bin:/bin:/usr/sbin:/sbin"
<com.apple.tools.product-pkg-utility> "/Users/ainutveckling/Library/MobileDevice/Provisioning Profiles/F792F2E5-45DB-43C7-969C-6012C59BF778.mobileprovision" -o /Users/ainutveckling/Jenkins/workspace/CallControl_iPhoneContiousBuild/Callcontrol/build/Distribution-iphoneos/CallControl.app/embedded.mobileprovision
** BUILD FAILED **
+ failed build
+ echo 'Failed: build'
Failed: build
+ exit 1
Notifying upstream projects of job completion
Finished: FAILURE
On my machine, it looks almost the same:
GenerateDSYMFile build/Distribution-iphoneos/CallControl.app.dSYM build/Distribution-iphoneos/CallControl.app/CallControl
cd /Users/anders/Utveckling/CallControl/iphone/totala_samtalslistan/Callcontrol
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/anders/Utveckling/android-sdk-mac_x86/tools:/Users/anders/Utveckling/android-sdk-mac_x86/platform-tools:"
/Developer/usr/bin/dsymutil /Users/anders/Utveckling/CallControl/iphone/totala_samtalslistan/Callcontrol/build/Distribution-iphoneos/CallControl.app/CallControl -o /Users/anders/Utveckling/CallControl/iphone/totala_samtalslistan/Callcontrol/build/Distribution-iphoneos/CallControl.app.dSYM
ProcessProductPackaging "/Users/anders/Library/MobileDevice/Provisioning Profiles/F792F2E5-45DB-43C7-969C-6012C59BF778.mobileprovision" build/Distribution-iphoneos/CallControl.app/embedded.mobileprovision
cd /Users/anders/Utveckling/CallControl/iphone/totala_samtalslistan/Callcontrol
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/anders/Utveckling/android-sdk-mac_x86/tools:/Users/anders/Utveckling/android-sdk-mac_x86/platform-tools:"
<com.apple.tools.product-pkg-utility> "/Users/anders/Library/MobileDevice/Provisioning Profiles/F792F2E5-45DB-43C7-969C-6012C59BF778.mobileprovision" -o /Users/anders/Utveckling/CallControl/iphone/totala_samtalslistan/Callcontrol/build/Distribution-iphoneos/CallControl.app/embedded.mobileprovision
** BUILD SUCCEEDED **
But success...
It does not matter if I start the build directly from the command line on the build machine or if it is started by Hudson, same result.
The certificate pointed out above seems to be in place.
I'm almost ready to give up on this, so I would very much appreciate any help to shed some light upon the matter!
Best regards,
Anders
I encountered the exact error that you showed above on my build machine after updating to a new distribution certificate and provisioning profile. After the ProcessProductPackaging step, it would just display the ** BUILD FAILED ** message.
However, when running the build manually on the build machine, I encountered the KeyChain permission dialog. Hitting "Allow Always" fixed the problem.
That in addition to unlocking in the build script:
security unlock -p $PASSWORD
Add this line of code to your script:
security list-keychains -s $KEYCHAINFILE
This has fixed the issue for me.