How can I use swift in Terminal?

后端 未结 13 557
北荒
北荒 2020-11-29 15:28

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 inter

相关标签:
13条回答
  • 2020-11-29 16:20

    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".

    0 讨论(0)
提交回复
热议问题