Swift Grammar
!从各路教程官方文档节选的内容➕一些个人理解
适合
初学者考试突击
和
需要短时间快速浏览swift语言特点
的朋友
Introduction
Swift doesn't have header file
Compiled language
Variables、Constants、Literals
Variables | Constants |
---|---|
var | let |
A literal is the source code representation of a value of an integer, floating-point number, or string type.
起名:可以是任意unicode表示的包括pi,包括emoji,但是数学符号箭头空格不行,且不能以数字开头。
Definition:
var siteName:String = "Northeastern"
var id: Int
- 类型注释 Type annotation: let money : Int = 15
- 类型推论 Type Inference: let thisIsInteger = 15
Boolean:
Swift has type safety, which prevent non-Boolean values using as bool
即不能用1和0代替true和false
Operations
Range
Operator | Description |
---|---|
闭区间 | (a...b) defines a range that runs from a to b, and includes the values a and b. |
半开半闭区间 | (a..< b) defines a range that runs from a to b, but does not include b. |
单边区间 | a... or ...a defines a range that runs from a to end of elements or form start of elements to a |
Ternery Condition
Condition ? X : Y
If Condition is true ? Then value X : Otherwise value Y
Identity Operators
=== and !==
References are to the same object instance
String and Characters
Create Character
let char : Character = “?”
let catCharacters: [ Character ] = ["C", "a", "t", "!", "
标签:速通,Int,value,语法,print,let,var,Swift,String
From: https://www.cnblogs.com/Lamplight/p/16840427.html