Swift源碼簡介
- Swift于2015年正式開源,github地址:https://github.com/apple/swift
- 幾個可能會經(jīng)??吹哪夸洠?br>
- docs:一些文檔
- stdlib:Swift源碼
- lib:c++源碼
- include:c++頭文件 - 標準庫源碼位置(標準庫:
Int、Double、Array、Dictionary等等常用類型都屬于標準庫)https://github.com/apple/swift/tree/master/stdlib/public/core
把標準庫代碼下載到本地,可以把stdlib/public/core里邊的代碼拖入到工程中去看,在拖入時,不需要編譯不需要拷貝,僅僅供看代碼,在勾選時,可以僅勾選如下選項:
Array分析
-
map、filter
https://github.com/apple/swift/blob/master/stdlib/public/core/Sequence.swift -
flatMap、compactMap、reduce
https://github.com/apple/swift/blob/master/stdlib/public/core/SequenceAlgorithms.swift
Substring分析
-
append、lowercased、uppercased
https://github.com/apple/swift/blob/master/stdlib/public/core/Substring.swift
Optional分析
-
map、flatMap、==、??
https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift
Metadata分析
https://github.com/apple/swift/blob/master/docs/ABI/TypeMetadata.rst
反射
- 反射是編程語言中一項強大的能力,比如Java語言的反射機制
- 對于任意一個類型,都能夠動態(tài)獲取這個類的所有屬性和方法信息
- 對于任意一個實例,都能夠動態(tài)調用它的任意方法和屬性 - Swift的反射機制目前還比較弱,通過
Mirror類型來提供簡單的反射功能
