對蘋果「五仁」編程語言Swift的簡單分析

對蘋果「五仁」編程語言Swift的簡單分析

蘋果在昨天的WWDC上,公佈了新的編程語言Swift。這兩天開發社區都在討論這個語言,從語言的特性上你們發現了好多語言的影子,這種狀況可以說是集大成,也可以說是「五仁」。

每個人看問題的角度都不一樣,如下從我的的角度來看看這門語言涉及到的工具鏈及其對越獄開發的影響。node

由於剛剛公佈。針對相關工具的介紹差點兒沒有,那咱們就從xcode中尋找。在shell中運行:

find /Applications/Xcode6-Beta.app/Contents/ -name "*swift*"

可以找到swift相關的文件,簡單過濾後,例如如下的文件比較重要:

/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-demangle
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-ide-test
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-stdlib-tool
/Applications/Xcode6-Beta.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/repl_swift
/Applications/Xcode6-Beta.app/Contents//Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man/man1/swift.1

從找到的文件裏咱們可以看到包括 man 手冊文件。咱們首先看看手冊的內容:
swift(1)                                   Swift Documentation                                  swift(1)

NAME
       swift - <strong>the amazingly new programming language</strong>

SYNOPSIS
       swift [-emit-object|-emit-assembly|-emit-library|-i]
         [-help]
         -o output-file
         input-filenames

       The full list of supported options is available via "swift -help".

DESCRIPTION
       Swift is a new, high performance systems programming language.  It has a clean and modern syntax,
       and offers seamless access to existing C and Objective-C code and frameworks, and is memory safe
       (by default).

       Although inspired by Objective-C and many other languages, Swift is not itself a C-derived
       language. As a complete and independent language, Swift packages core features like flow control,
       data structures, and functions, with high-level constructs like objects, protocols, closures, and
       generics.  Swift embraces modules, eliminating the need for headers and the code duplication they
       entail.

                                               2014-05-17                                       swift(1)


從手冊中可以獲得的信息也頗有限,但是看到參數:-help,咱們看看幫助會輸出什麼:
OVERVIEW: Swift compiler

USAGE: swift [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)
  -integrated-repl Integrated REPL mode
  -i               Immediate mode
  -lldb-repl       LLDB-enhanced REPL mode
  -parse           Parse input file(s)
  -print-ast       Parse and type-check input file(s) and pretty print AST(s)
  -repl            REPL mode

OPTIONS:
  -application-extension  Restrict code to those available for App Extensions
  -arch <arch>            Compile for architecture <arch>
  -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
  -output-file-map <path> A file which specifies the location of outputs
  -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
  -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-feature [+-]<feature-name>
                          Generate code with a particular CPU feature enabled or disabled
  -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
  -Xfrontend <arg>        Pass <arg> to the Swift frontend
  -Xlinker <value>        Specifies an option which should be passed to the linker
  -Xllvm <arg>            Pass <arg> to LLVM.

這麼多參數究竟怎麼用呢?。咱們一塊兒來看看 xcode 是怎麼使用的。ios

 

打開xcode6新建一個空project,取名「FuckSwift」:



將project的Deployment Target改爲 5.0,而後編譯,並在設備上執行。我手上的設備是iPad2-iOS7.0.4,可以正常執行。爲何可以正常執行?swift相關的執行時庫怎麼處理?咱們打開編譯好的app文件夾:



可以看到比曾經的程序多了一個文件夾 Frameworks,內容例如如下:



所以,在iOS8之下的設備上,程序打包的時候帶上了必要的執行庫。shell

對於iOS8,眼下還無法解開 dyld cache 也就沒法知道設備上是否帶了這些庫,只是應該會帶。express

 

接上文,咱們創建測試project的目的是爲了看看 xcode 怎樣使用 swift 編譯工具,xcoce編譯時的相關參數例如如下:
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift 
-target armv7-apple-ios5.0 
-module-name FuckSwift 
-O0 
-sdk /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk 
-g 
-module-cache-path /Users/proteas/Library/Developer/Xcode/DerivedData/ModuleCache 
-I /Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Products/Debug-iphoneos 
-F /Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Products/Debug-iphoneos 
-parse-as-library 
-c 
-j8 
/Users/proteas/Desktop/FuckSwift/FuckSwift/AppDelegate.swift 
-output-file-map /Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/Objects-normal/armv7/FuckSwift-OutputFileMap.json 
-serialize-diagnostics 
-emit-dependencies 
-emit-module 
-emit-module-path /Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/Objects-normal/armv7/FuckSwift.swiftmodule 
-Xcc 
-iquote 
-Xcc /Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/FuckSwift-generated-files.hmap 
-Xcc -I/Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/FuckSwift-own-target-headers.hmap 
-Xcc -I/Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/FuckSwift-all-target-headers.hmap 
-Xcc 
-iquote 
-Xcc /Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/FuckSwift-project-headers.hmap -Xcc -I/Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Products/Debug-iphoneos/include 
-Xcc 
-I/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include 
-Xcc -I/Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/DerivedSources/armv7 
-Xcc -I/Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/DerivedSources 
-Xcc 
-DDEBUG=1 
-emit-objc-header 
-emit-objc-header-path /Users/proteas/Library/Developer/Xcode/DerivedData/FuckSwift-czflmbyelvdrnvaxblvpkcrhfbie/Build/Intermediates/FuckSwift.build/Debug-iphoneos/FuckSwift.build/Objects-normal/armv7/FuckSwift-Swift.h

參數仍是太多。繼續精簡,把去掉絕對路徑:
swift 	-target armv7-apple-ios5.0
		-module-name FuckSwift
		-O0
		-sdk iPhoneOS8.0.sdk
		-g
		-module-cache-path ModuleCache
		-I Debug-iphoneos 
		-F Debug-iphoneos 
		-parse-as-library 
		-c 
		-j8 
		AppDelegate.swift 
		-output-file-map FuckSwift-OutputFileMap.json 
		-serialize-diagnostics 
		-emit-dependencies 
		-emit-module 
		-emit-module-path FuckSwift.swiftmodule 
		-Xcc -iquote 
		-Xcc FuckSwift-generated-files.hmap 
		-Xcc -IFuckSwift-own-target-headers.hmap 
		-Xcc -IFuckSwift-all-target-headers.hmap 
		-Xcc -iquote 
		-Xcc FuckSwift-project-headers.hmap 
		-Xcc -Iinclude 
		-Xcc -I/usr/include 
		-Xcc -Iarmv7 
		-Xcc -IDerivedSources 
		-Xcc -DDEBUG=1 
		<strong>-emit-objc-header 
		-emit-objc-header-path FuckSwift-Swift.h</strong>

這樣就相對清晰了。這裏面的參數你們可以對比上述的幫助查看。這裏咱們一塊兒看兩點:編程

一、Xcc <arg>:Pass <arg> to the C/C++/Objective-C compiler,這裏咱們可以獲得:swift代碼很是可能終於被轉變成C/C++/Objective-C代碼進行靜態編譯json

二、會生成FuckSwift-Swift.h頭文件,對照下這個文件與swift文件。

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { self.window = UIWindow(frame: UIScreen.mainScreen().bounds) self.window!.backgroundColor = UIColor.whiteColor() self.window!.makeKeyAndVisible() return true } func applicationWillResignActive(application: UIApplication) { } func applicationDidEnterBackground(application: UIApplication) { } func applicationWillEnterForeground(application: UIApplication) { } func applicationDidBecomeActive(application: UIApplication) { } func applicationWillTerminate(application: UIApplication) { } } swift


SWIFT_CLASS("_TtC9FuckSwift11AppDelegate")
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic) UIWindow * window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
- (void)applicationWillResignActive:(UIApplication *)application;
- (void)applicationDidEnterBackground:(UIApplication *)application;
- (void)applicationWillEnterForeground:(UIApplication *)application;
- (void)applicationDidBecomeActive:(UIApplication *)application;
- (void)applicationWillTerminate:(UIApplication *)application;
- (instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

可以看到swift程序是被轉換了的,但是是否是轉換成了Objective-C程序呢?還需要進一步分析。xcode

打開IDA,載入測試程序的MachO:數據結構



咱們重點看下函數窗體:
app


從函數名上咱們可以獲得例如如下結論:

一、可以看到函數名被「改編」了。

二、swift代碼並不是被簡單得編譯成了ObjC代碼

三、swift代碼終於被編譯成了純C代碼,相對於ObjC來講省去了執行時查表進行函數調用的開銷,執行效率應該比ObjC要高。

四、從文檔上看swfit相對於ObjC來講是更加動態的語言,開發效率也應該比ObjC高

五、對於越獄開發來講,咱們僅僅要像Hook C函數那樣來Hook swift 函數就可以了。所以MobileSubstrate仍是可以工做的。

六、生成的代碼仍是要遵循 ARM 的ABI標準

 

就像C++的名稱改編同樣。改編後的名稱儘管可以手工還原但是太麻煩。最好找到工具來作這一件事。前文,咱們在查找swift相關的文件時看到一個工具:swift-demangle,如下咱們就用它來demangle改編後的名稱,看看可以獲得什麼。

首先,咱們切換命令行到xcode6的命令行工具:

sudo xcode-select --switch /Applications/Xcode6-Beta.app/Contents/Developer

而後,咱們看看swift-demangle的命令行參數:

USAGE: swift-demangle [options] [mangled name...]

OPTIONS:
  -compact   - Compact mode (only emit the demangled names)
  -expand    - Expand mode (show node structure of the demangling)
  -help      - Display available options (-help-hidden for more)
  -no-sugar  - No sugar mode (disable common language idioms such as ? and [] from the output)
  -tree-only - Tree-only mode (do not show the demangled string)
  -version   - Display the version of this program

從IDA中複製一個函數名,如:

__TToFC9FuckSwift11AppDelegate26applicationDidBecomeActivefS0_FCSo13UIApplicationT_

咱們運行例如如下命令:

xcrun swift-demangle "__TToFC9FuckSwift11AppDelegate26applicationDidBecomeActivefS0_FCSo13UIApplicationT_"

獲得輸出:

_TToFC9FuckSwift11AppDelegate26applicationDidBecomeActivefS0_FCSo13UIApplicationT_ ---> @objc FuckSwift.AppDelegate.applicationDidBecomeActive (FuckSwift.AppDelegate)(ObjectiveC.UIApplication) -> ()

可以看到函數被還原。

到這裏咱們停下,看看swift對越獄開發的影響:

一、眼下沒法使用class-dump獲得ObjC的頭文件。

二、MobileSubstrate應該還可以正常工做。

三、可以使用demangle工具還原函數名,後期這部分工做IDA可能會本身主動支持。

總之,對越獄開發的流程會略微有影響,針相應用的越獄開發還可以存在。



如下咱們看看命令行工具swift-ide-test的參數:

OVERVIEW: Swift IDE Test

USAGE: swift-ide-test [options] [input files...]

OPTIONS:
  -D=<string>                              - Build configurations
  -F=<string>                              - add a directory to the framework search path
  -I=<string>                              - add a directory to the import search path
  -annotate-print                          - Annotate AST printing
  -code-completion-diagnostics             - Print compiler diagnostics while doing code completion
  -code-completion-token=<string>          - Code completion token name
  -comments-xml-schema=<string>            - Filename of the RelaxNG schema for documentation comments
  -enable-objc-factory-method-constructors - Implicitly import Objective-C factory methods as initializers
  -enable-objc-implicit-properties         - Implicitly import Objective-C getter/setter pairs as properties
  -explode-pattern-binding-decls           - Separate pattern binding decls into individual var decls
  -fatal-assembler-warnings                - Consider warnings as error
  -fully-qualified-types                   - Print fully qualified types
  -fully-qualified-types-if-ambiguous      - Print types fully-qualified if they would be ambiguous otherwise
  -function-definitions                    - Print function bodies
  -help                                    - Display available options (-help-hidden for more)
  -implicit-objc-with                      - Make the "with" implicit in initializers
  -import-objc-header=<string>             - header to implicitly import
  -module-cache-path=<string>              - Clang module cache path
  -module-print-hidden                     - Print non-exported imported or submodules
  -module-print-skip-overlay               - Skip Swift overlay modules
  -module-print-submodules                 - Recursively print submodules
  -module-to-print=<string>                - Name of the module to print
  -objc-bridge-dictionary                  - Bridge Dictionary<K, V> to NSDictionary
  -prefer-type-repr                        - When printing types, prefer printing TypeReprs
  -print-after-all                         - Print IR after each pass
  -print-before-all                        - Print IR before each pass
  Mode:
    -code-completion                       - Perform code completion
    -repl-code-completion                  - Perform REPL-style code completion
    -syntax-coloring                       - Perform syntax coloring
    -structure                             - Perform document structure annotation
    -annotate                              - Perform semantic annotation
    -test-input-complete                   - Check if input source is complete
    -print-ast-not-typechecked             - Print the non-typechecked AST
    -print-ast-typechecked                 - Print the typechecked AST
    -print-module                          - Print visible declarations in a module
    -print-types                           - Print types of all subexpressions and declarations in the AST
    -print-comments                        - Print documentation comments attached to decls
    -print-module-comments                 - Given a module, print documentation comments attached to decls
    -print-module-imports                  - Recursively print all imports visible from a particular module
    -print-usrs                            - Print USRs for all decls
    -parse-rest                            - Parse a ReST file
  -print-implicit-attrs                    - Print implicit attributes
  -print-regular-comments                  - Print regular comments from clang module headers
  -print-stats                             - Print statistics
  -sdk=<string>                            - path to the SDK to build against
  -skip-private-stdlib-decls               - Don't print declarations that start with '_'
  -skip-unavailable                        - Don't print unavailable declarations
  -source-filename=<string>                - Name of the source file
  -split-objc-selectors                    - Split Objective-C selectors
  -stats                                   - Enable statistics output from program (available with Asserts)
  -synthesize-sugar-on-types               - Always print Array and Optional with sugar
  -target=<string>                         - target triple
  -terminal                                - Use terminal color for source annotations
  -time-passes                             - Time each pass, printing elapsed time for each on exit
  -typecheck                               - Type check the AST
  -version                                 - Display the version of this program

從參數上看。這很是多是xcode的內部工具,用來作代碼完畢與檢查的。這裏不詳細分析。感興趣的兄弟可以本身試試。

 

如下咱們繼續回到 swift 工具上,首先看看parse的輸出。運行例如如下命令:

xcrun swift AppDelegate.swift -dump-parse

獲得例如如下輸出:

(source_file
  (import_decl UIKit')
  (class_decl "AppDelegate" type='<null type>' inherits: <null>, <null>
    (pattern_binding_decl
      (pattern_typed
        (pattern_named 'window')
))
    (var_decl "window" type='<null type>' storage_kind='stored')
    (func_decl "application(_:didFinishLaunchingWithOptions:)" type='<null type>'
      (body_params
        (pattern_typed implicit
          (pattern_named implicit 'self'))
        (pattern_tuple
          (pattern_typed
            (pattern_named 'application')
            (type_ident
              (component id='UIApplication' bind=none)))
          (pattern_typed
            (pattern_named 'launchOptions')
)))
      (result
        (type_ident
          (component id='Bool' bind=none)))
      (brace_stmt
        (sequence_expr type='<null>'
          (unresolved_dot_expr type='<null>' field 'window'
            (declref_expr type='<null>' decl=AppDelegate.(file).AppDelegate.func decl.self@AppDelegate.swift:17:10 specialized=yes))
          (assign_expr
            (**NULL EXPRESSION**)
            (**NULL EXPRESSION**))
          (call_expr type='<null>'
            (unresolved_decl_ref_expr type='<null>' name=UIWindow specialized=no)
            (tuple_expr type='<null>' names=frame
              (unresolved_dot_expr type='<null>' field 'bounds'
                (call_expr type='<null>'
                  (unresolved_dot_expr type='<null>' field 'mainScreen'
                    (unresolved_decl_ref_expr type='<null>' name=UIScreen specialized=no))
                  (tuple_expr type='<null>'))))))
        (sequence_expr type='<null>'
          (unresolved_dot_expr type='<null>' field 'backgroundColor'
            (force_value_expr type='<null>'
              (unresolved_dot_expr type='<null>' field 'window'
                (declref_expr type='<null>' decl=AppDelegate.(file).AppDelegate.func decl.self@AppDelegate.swift:17:10 specialized=yes))))
          (assign_expr
            (**NULL EXPRESSION**)
            (**NULL EXPRESSION**))
          (call_expr type='<null>'
            (unresolved_dot_expr type='<null>' field 'whiteColor'
              (unresolved_decl_ref_expr type='<null>' name=UIColor specialized=no))
            (tuple_expr type='<null>')))
        (call_expr type='<null>'
          (unresolved_dot_expr type='<null>' field 'makeKeyAndVisible'
            (force_value_expr type='<null>'
              (unresolved_dot_expr type='<null>' field 'window'
                (declref_expr type='<null>' decl=AppDelegate.(file).AppDelegate.func decl.self@AppDelegate.swift:17:10 specialized=yes))))
          (tuple_expr type='<null>'))
        (return_stmt
          (unresolved_decl_ref_expr type='<null>' name=true specialized=no))))
    (func_decl "applicationWillResignActive(_:)" type='<null type>'
      (body_params
        (pattern_typed implicit
          (pattern_named implicit 'self'))
        (pattern_tuple
          (pattern_typed
            (pattern_named 'application')
            (type_ident
              (component id='UIApplication' bind=none)))))
      (brace_stmt))
    (func_decl "applicationDidEnterBackground(_:)" type='<null type>'
      (body_params
        (pattern_typed implicit
          (pattern_named implicit 'self'))
        (pattern_tuple
          (pattern_typed
            (pattern_named 'application')
            (type_ident
              (component id='UIApplication' bind=none)))))
      (brace_stmt))
    (func_decl "applicationWillEnterForeground(_:)" type='<null type>'
      (body_params
        (pattern_typed implicit
          (pattern_named implicit 'self'))
        (pattern_tuple
          (pattern_typed
            (pattern_named 'application')
            (type_ident
              (component id='UIApplication' bind=none)))))
      (brace_stmt))
    (func_decl "applicationDidBecomeActive(_:)" type='<null type>'
      (body_params
        (pattern_typed implicit
          (pattern_named implicit 'self'))
        (pattern_tuple
          (pattern_typed
            (pattern_named 'application')
            (type_ident
              (component id='UIApplication' bind=none)))))
      (brace_stmt))
    (func_decl "applicationWillTerminate(_:)" type='<null type>'
      (body_params
        (pattern_typed implicit
          (pattern_named implicit 'self'))
        (pattern_tuple
          (pattern_typed
            (pattern_named 'application')
            (type_ident
              (component id='UIApplication' bind=none)))))
      (brace_stmt))))

由於不瞭解編譯器相關的知識,沒法解析上述輸出,但是看起來很是像common lisp 的「點對」數據結構。


另外。咱們會注意到還有一個比較重要的命令行參數:-repl。咱們一塊兒玩玩,看看這個工具能力怎麼樣。

在命令行運行例如如下命令:

xcrun swift -repl

可以獲得一個腳本解析器的運行環境:


咱們參考「The Swift Programming Language」寫一個Hello World,看看效果:



可以使用:Ctrl + D退出解析器。

這裏可以獲得:

一、swift既可以被編譯運行,也可以被解析運行,是真正的動態語言

二、你們可以用這個工具來學習語言特性。

 

就分析到這裏。但願對你們有幫助。

相關文章
相關標籤/搜索