零基础学习 Swift,建议可以先阅读官方编排的教学架构,获取基础观念、认知
Swift 官方社群
https://swift.org/
正体中文版苹果 Swift 官方教学《The Swift Programming Language》
https://tommy60703.gitbooks.io/swift-language-traditional-chinese/content/index.html
随意点阅,对於零基础的人来说,是不是光看就昏头了呢xd
让我们先学习以下十个基础观念吧!
变数
- 宣告变数(Variable)使用
var
- 使用关键字 var 宣告的是变数,储存的值可以不断改变
常数
- 宣告常数(Constant)使用
let
- 使用关键字 let 宣告的是常数,储存的值只能设定一次,之後不能改变
基本运算子
- 一元(Unary Operator),二元(Binary Operator)和三元运算子(Ternary Operator)
- 指派运算子 (Assignment Operator)
- 数值运算子(Arithmetic Operator)
- 复合指派运算子 (Compound Assignment Operator)
- 比较运算子 (Comparison Operator)
- 三元条件运算(Ternary Conditional Operator)
表达式
- 前缀表达式(Prefix Expressions)
- 二元表达式(Binary Expressions)
- 赋值表达式(Assignment Operator)
- 三元条件运算子(Ternary Conditional Operator)
- 型别转换运算子(Type-Casting Operators)
- 主要表达式(Primary Expressions)
- 後缀表达式(Postfix Expressions)
流程控制
- For 回圈
- While 回圈
- 条件语句
- 控制转移语句(Control Transfer Statements)
函式
- 函式定义与呼叫(Defining and Calling Functions)
- 函式参数与回传值(Function Parameters and Return Values)
- 函式参数名称(Function Parameter Names)
- 函式型别(Function Types)
- 函式嵌套(Nested Functions)
集合型别
- 阵列型别(Array Type)
- 字典型别(Dictionary Type)
- 元组型别(Tuple Type)
类别
- 物件与类别
- 物件初始化
- 物件的属性(property)
- 物件的方法(method)
- optional 物件变数
- 类别的继承
- 初始化过程
- 方法与属性的覆写
- 类别的方法与属性
- 权限管理
协定
- 协定的语法(Protocol Syntax)
- 属性要求(Property Requirements)
- 方法要求(Method Requirements)
- 突变方法要求(Mutating Method Requirements)
- 协定型别(Protocols as Types)
- 委托(代理)模式(Delegation)
- 在扩展中添加协定成员(Adding Protocol Conformance with an Extension)
- 通过扩展补充协定宣告(Declaring Protocol Adoption with an Extension)
- 集合中的协定型别(Collections of Protocol Types)
- 协定的继承(Protocol Inheritance)
- 协定合成(Protocol Composition)
- 检验协定的一致性(Checking for Protocol Conformance)
- 可选协定要求(Optional Protocol Requirements)
闭包
- 闭包表达式(Closure Expressions)
- 尾随闭包(Trailing Closures)
- 值捕获(Capturing Values)
- 闭包是参考型别(Closures Are Reference Types)