Rodhos Soft

備忘録を兼ねた技術的なメモです。Rofhos SoftではiOSアプリ開発を中心としてAndroid, Webサービス等の開発を承っております。まずはご相談下さい。

コマンドライン

参考
yamaimo.hatenablog.jp


コンパイルする場合はswiftcを使う。

$ 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)
  -dump-scope-maps <expanded-or-list-of-line:column>
                   Parse and type-check input file(s) and dump the scope map(s)
  -dump-type-refinement-contexts
                   Type-check input file(s) and dump type refinement contexts(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-sibgen     Emit serialized AST + raw SIL file(s)
  -emit-sib        Emit serialized AST + canonical SIL file(s)
  -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)
  -typecheck       Parse and type-check input file(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, Unchecked, DisableReplacement.
  -continue-building-after-errors
                          Continue building, even after errors are encountered
  -driver-time-compilation
                          Prints the total time it took to execute all compilation tasks
  -D <value>              Marks a conditional compilation flag as true
  -embed-bitcode-marker   Embed placeholder LLVM IR data as a marker
  -embed-bitcode          Embed LLVM IR bitcode as data
  -emit-dependencies      Emit basic 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
  -fixit-all              Apply all fixits from diagnostics without any filtering
  -fixit-code             Get compiler fixits as code edits
  -framework <value>      Specifies a framework which should be linked against
  -F <value>              Add directory to framework search path
  -gdwarf-types           Emit full DWARF type info.
  -gline-tables-only      Emit minimal debug info for backtraces only
  -gnone                  Don't emit debug info
  -g                      Emit debug info. This is the preferred setting for debugging with LLDB.
  -help                   Display available options
  -import-underlying-module
                          Implicitly imports the Objective-C half of a module
  -index-store-path <path>
                          Store indexing data to <path>
  -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
  -num-threads <n>        Enable multi-threading and specify number of threads
  -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
  -profile-coverage-mapping
                          Generate coverage data for use with profiled execution counts
  -profile-generate       Generate instrumented code to collect execution counts
  -sanitize-coverage=<type>
                          Specify the type of coverage instrumentation for Sanitizers and additional options separated by commas
  -sanitize=<check>       Turn on runtime checks for erroneous behavior.
  -save-temps             Save intermediate compilation results
  -sdk <sdk>              Compile against <sdk>
  -serialize-diagnostics  Serialize diagnostics in a binary format
  -static-executable      Statically link the executable
  -static-stdlib          Statically link the Swift standard library
  -suppress-warnings      Suppress all warnings
  -swift-version <vers>   Interpret input according to a specific Swift language version number
  -target-cpu <value>     Generate code for a particular CPU variant
  -target <value>         Generate code for the given target
  -tools-directory <directory>
                          Look for external executables (ld, clang, binutils) in <directory>
  -use-ld=<value>         Specifies the linker to be used
  -version                Print version information and exit
  -v                      Show commands to run and use verbose output
  -warnings-as-errors     Treat warnings as errors
  -whole-module-optimization
                          Optimize input files together instead of individually
  -Xcc <arg>              Pass <arg> to the C/C++/Objective-C compiler
  -Xlinker <value>        Specifies an option which should be passed to the linker

そしてswiftというコマンドもある。

$ swift -h
OVERVIEW: Swift compiler

USAGE: swift [options] <inputs>

OPTIONS:
  -assert-config <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Unchecked, DisableReplacement.
  -continue-building-after-errors
                         Continue building, even after errors are encountered
  -D <value>             Marks a conditional compilation flag as true
  -framework <value>     Specifies a framework which should be linked against
  -F <value>             Add directory to framework search path
  -gdwarf-types          Emit full DWARF type info.
  -gline-tables-only     Emit minimal debug info for backtraces only
  -gnone                 Don't emit debug info
  -g                     Emit debug info. This is the preferred setting for debugging with LLDB.
  -help                  Display available options
  -index-store-path <path>
                         Store indexing data to <path>
  -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
  -num-threads <n>       Enable multi-threading and specify number of threads
  -Onone                 Compile without any optimization
  -Ounchecked            Compile with optimizations and remove runtime safety checks
  -O                     Compile with optimizations
  -sdk <sdk>             Compile against <sdk>
  -static-executable     Statically link the executable
  -static-stdlib         Statically link the Swift standard library
  -suppress-warnings     Suppress all warnings
  -swift-version <vers>  Interpret input according to a specific Swift language version number
  -target-cpu <value>    Generate code for a particular CPU variant
  -target <value>        Generate code for the given target
  -use-ld=<value>        Specifies the linker to be used
  -version               Print version information and exit
  -v                     Show commands to run and use verbose output
  -warnings-as-errors    Treat warnings as errors
  -Xcc <arg>             Pass <arg> to the C/C++/Objective-C compiler
  -Xlinker <value>       Specifies an option which should be passed to the linker

Swiftは対話モードで実行できる。

$ swift
Welcome to Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42). Type :help for assistance.
  1> 3+2
$R0: Int = 5
  2> class A { 
  3.     var hoge:Int? = nil 
  4.     func hello() { 
  5.         print("hello \(hoge)") 
  6.     } 
  7. } 
  8> let a = A()
a: A = {
  hoge = nil
}
  9> a.hoge = 100
 10> a.hello()
hello Optional(100)
 11>