应公司的要求,要我研究swift语言,然后给大家进行swift技术培训,买了4,5本swift相关的书籍就开始研究了.
今天来介绍一下,swft相关的终端的命令.
1.首先我们在桌面上建一个swift文件夹用来存放.swift源文件,
打开终端输入cd 加空格 拖拽文件夹到终端(使用命令 ls ,cd 目录也是等效)
cd /Users/mac/Desktop/swfit
</pre><p></p><p>2.要创建和编译运行swift源文件,需要使用 swiftc 命令,并且配以相关的options参数</p><p>如下,我们查看一下,swiftc 的相关参数和用法,</p><p>输入 swiftc --help可以看到如下的参数的说明,大家可以根据后面的注释来使用swiftc命令</p><p></p><pre name="code" class="objc">yangbindeMacBook-Air:swfit mac$ swiftc --help
OVERVIEW: Swift compiler
USAGE: swiftc [options] <inputs>
MODES:
-dump-ast Parse and type-check input file(s) and dump AST(s)
-dump-parse Parse input file(s) and dump AST(s)
-emit-assembly Emit assembly file(s) (-S)
-emit-bc Emit LLVM BC file(s)
-emit-executable Emit a linked executable
-emit-ir Emit LLVM IR file(s)
-emit-library Emit a linked library
-emit-object Emit object file(s) (-c)
-emit-silgen Emit raw SIL file(s)
-emit-sil Emit canonical SIL file(s)
-parse Parse input file(s)
-print-ast Parse and type-check input file(s) and pretty print AST(s)
OPTIONS:
-application-extension Restrict code to those available for App Extensions
-assert-config <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Replacement.
-D <value> Specifies one or more build configuration options
-emit-dependencies Emit Make-compatible dependencies files
-emit-module-path <path>
Emit an importable module to <path>
-emit-module Emit an importable module
-emit-objc-header-path <path>
Emit an Objective-C header file to <path>
-emit-objc-header Emit an Objective-C header file
-framework <value> Specifies a framework which should be linked against
-F <value> Add directory to framework search path
-g Emit debug info
-help Display available options
-import-underlying-module
Implicitly imports the Objective-C half of a module
-I <value> Add directory to the import search path
-j <n> Number of commands to execute in parallel
-L <value> Add directory to library link search path
-l<value> Specifies a library which should be linked against
-module-cache-path <value>
Specifies the Clang module cache path
-module-link-name <value>
Library to link against when using this module
-module-name <value> Name of the module to build
-nostdimport Don't search the standard library import path for modules
-Onone Compile without any optimization
-Ounchecked Compile with optimizations and remove runtime safety checks
-output-file-map <path> A file which specifies the location of outputs
-O Compile with optimizations
-o <file> Write output to <file>
-parse-as-library Parse the input file(s) as libraries, not scripts
-parse-sil Parse the input file as SIL code, not Swift source
-parseable-output Emit textual output in a parseable format
-save-temps Save intermediate compilation results
-sdk <sdk> Compile against <sdk>
-serialize-diagnostics Serialize diagnostics in a binary format
-target-cpu <value> Generate code for a particular CPU variant
-target <value> Generate code for the given target
-version Print version information and exit
-v Show commands to run and use verbose output
-Xcc <arg> Pass <arg> to the C/C++/Objective-C compiler
-Xlinker <value> Specifies an option which should be passed to the linker
进入swift文件夹后,然后使用如下的命令创建
vi HelloWorld.swift然后在文本中创建代码,打印出helloworld
println("Hello这是我的第一个swift程序!")然后 按一次Esc 键, shfit +分号键,接着 输入wq ,回车
保存并且推出vi
4.然后,在swift目录下,编译 swift源文件,使用swiftc -o 参数
swiftc -o Hello.out HelloWorld.swift可以看到在 swift目录下生成了一个 .out后缀的文件
hello.out是输出文件的类型,是mac上可以直接执行的程序,可以使用终端运行
例如,直接拖拽该.out文件到终端,然后回车可以看到终端执行了该文件并且输出结果如下:
Hello 这是我的第一个swift程序!也可以在swift目录下,直接使用 ./Hello.out来执行,效果等价
./Hello.out
yangbindeMacBook-Air:swfit mac$ Hello.out -bash: Hello.out: command not found yangbindeMacBook-Air:swfit mac$
这样就完成了,使用终端编译swift源程序,[OS X平台]
当然我们可以使用playground来替代一些简单的程序的测试
原文来自http://blog.csdn.net/yangbingbinga
swift研究01-使用switfc终端命令编译运行swift程序
原文地址:http://blog.csdn.net/yangbingbinga/article/details/44152943