一. 基本知識
swfit5.1后ABI 基本穩(wěn)定
-
API:Application Programming Interface
源代碼跟庫之間的接口 -
ABI: Application Binary Interface :應用程序二進制接口:應用程序跟操作系統(tǒng)的接口
3.OC跟swift的編譯器前端分別是:clang 和 swiftC 都存在在xcode里面
二. 一些關于SwiftC的簡單操作:<簡單了解>
- 導出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就是導出的意思 - OC 跟 swift生成的匯編代碼是一致的
三.Hello world
- 不需要編寫
main函數(shù),Swift將全局范圍內(nèi)的首句可執(zhí)行代碼作為程序的入口 -
var、let變量跟常量的確定,會自動推斷類型 - 直接打印變量
print(a),print(b),插入字符串打印print("hello world - \(a)")
四.Playground 的使用
可以快速的預覽代碼效果,首頁創(chuàng)建新的空工程
快捷鍵 command + Shift + enter 快速運行playground
快速預覽 UIKit, 不過還需要導入
import PlaygroundSupport預覽的代碼PlaygroundPage.current.liveView = viewview為 要展示視圖command + 0, command + 1隱藏跟展示側邊欄多個頁面的展示, 點擊 playground 新建,注意 source 文件夾的文件目錄
注釋:Swift 支持嵌套注釋。注釋支持
markup (類似 markDown)語法://: #一級標題MarkUp 語法只在playground里面有效
五.常量與變量
- 常量 只能賦值一次表明類型
let age:Int = 10
- 它的值不要求在編譯時確定:就是可以給一個常量賦值一個變量
- 變量跟常量在初始化之前都不允許被使用
常見的數(shù)據(jù)類型
- 值類型:枚舉(
optional)、結構體(bool, Int,Float,Double,String,Array,Dictionary....) - 引用類型:類
class - 整數(shù)類型:
Int8,Int16,Int32,Int64,UInt8,UInt16.... -
print(Int16.max)取這個符號的最大值print(Int64.min) -
Bool值turefalse - 字符類型 也是雙引號,需要額外表明 :
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)