一. 基本知識
swfit5.1后ABI 基本穩(wěn)定
-
API
:Application Programming Interface
源代碼跟庫之間的接口 -
ABI
: Application Binary Interface :應(yīng)用程序二進(jìn)制接口:應(yīng)用程序跟操作系統(tǒng)的接口
3.OC
跟swift
的編譯器前端分別是:clang 和 swiftC 都存在在xcode里面
二. 一些關(guān)于SwiftC的簡單操作:<簡單了解>
- 導(dǎo)出swift文件的語法樹:
swiftc -dump-ast main.swift
- 生成簡潔的SIL代碼:
swiftc -emit-sil main.switf
就是swift的中間代碼 - 生成LLVM IR代碼:
swiftc -emit-ir main.swift -o main.ll
- 生成匯編代碼:
swiftc -emit-assembly main.swift -o main.s
后面-o main.s
就是導(dǎo)出的意思 - OC 跟 swift生成的匯編代碼是一致的
三.Hello world
- 不需要編寫
main
函數(shù)虾啦,Swift將全局范圍內(nèi)的首句可執(zhí)行代碼作為程序的入口 -
var
、let
變量跟常量的確定山害,會自動推斷類型 - 直接打印變量
print(a),print(b)
,插入字符串打印print("hello world - \(a)")
四.Playground 的使用
可以快速的預(yù)覽代碼效果,首頁創(chuàng)建新的空工程
快捷鍵 command + Shift + enter 快速運(yùn)行playground
快速預(yù)覽 UIKit, 不過還需要導(dǎo)入
import PlaygroundSupport
預(yù)覽的代碼PlaygroundPage.current.liveView = view
view
為 要展示視圖command + 0, command + 1
隱藏跟展示側(cè)邊欄多個頁面的展示, 點(diǎn)擊 playground 新建嘉涌,注意 source 文件夾的文件目錄
注釋:Swift 支持嵌套注釋。注釋支持
markup (類似 markDown)
語法://: #一級標(biāo)題
MarkUp 語法只在playground里面有效
五.常量與變量
- 常量 只能賦值一次表明類型
let age:Int = 10
- 它的值不要求在編譯時確定:就是可以給一個常量賦值一個變量
- 變量跟常量在初始化之前都不允許被使用
常見的數(shù)據(jù)類型
- 值類型:枚舉(
optional
)饼丘、結(jié)構(gòu)體(bool, Int,Float,Double,String,Array,Dictionary....)
- 引用類型:類
class
- 整數(shù)類型:
Int8,Int16,Int32,Int64,UInt8,UInt16....
-
print(Int16.max)
取這個符號的最大值print(Int64.min)
-
Bool
值ture
false
- 字符類型 也是雙引號趁桃,需要額外表明 :
character
類型轉(zhuǎn)換 元組
類型轉(zhuǎn)換
UInt16(b) + UInt16(a)
元組:多種數(shù)據(jù)類型的組合
(404,"error message")
let error = (404,"errormsg") print("errormsg = \(error.1)")
元組的描述:
let msgAndStatus = (statsuCode: 404,errorMsg:"Not found") print(msgAndStatus.statsuCode)