Swift 新手-语法基础

零基础学习 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)

<<:  [Day 17] Leetcode 56. Merge Intervals (C++)

>>:  [Day07] 第七章-简单介绍Laravel的操作及MVC架构

[Lesson20] ButterKnife

ButterKnife可以让我们在宣告元件时之後不用再打findViewById这行,可以帮忙省下宣...

Day6:进入新手村前先让我复习一下QQ-CSS-flexbox-用在内容物(item)的属性

这篇就要讲到flex可以使用在内容物(item)上的方法以及功能了!! order 这个语法是用来指...

时间管理

你的时间不是你的时间 当年当上管理者几个月之後,突然感觉到一阵茫然。我会发现都过了一个季了,为什麽...

【PHP Telegram Bot】Day05 - 程序语言的运作原理

众所皆知:「不会写程序的人都认为程序语言是写给电脑看的, 会写程序的人都知道程序语言是写给人看的。...

Day 06 「不听话就换掉」测试与依赖:测资料 之 用 Mock 工具控制依赖

2021 IT 铁人 Day 06 测试与依赖:测资料 之 用 Mock 工具控制依赖 今天要来聊的...