Recently in learning iOS development, take notes down!
Constants and variables
let maxNum =32
varindex0
- Declare multiple variables at the same time
var x=0.0,y=0.0,z=0.0
- Types can be inferred, or they can be explicitly declared
var0//这里是一个整形var str:String"123" //这是一个字符串
Basic type
int (integral type)
Double,float (floating point)
String (String)
BOOL (Boolean type)
Number Type
Decimal
Binary 0b101
Octal 0o5
Hex 0x5
Can be counted with science
let0.012let1.2e-2 //值为0.012
- Numbers can be separated by underscores
let1_000_000let1_0000_0000
let1let1.3232let num_c:Double = num_b + Double(num_a) //此处需要强制转换
Boolean type and if statement
The IF can be followed without parentheses, but curly braces are required.
The condition cannot be of another type, it must be a Boolean type
trueif isTrue{ println("is true") }else{ println("is false")}
- Tuple tuples
- Set multiple different values to a single data
var registrationResult = (true,"慕课女神","女")let (isRegisterSuccess,nickname,gender) = registrationResultisRegisterSucss //此处就为truenickname //"慕课女神"gender //"女"可以这样取值registrationResult.0 //此处就为trueregistrationResult.1 //"慕课女神"registrationResult.2 //"女"
- Omit part of a value by an underscore
let (isRegisterSuccess,_,_) = registrationResult
Optionals selectable values
- Or is a value, or there is no value
- Nil when there's no value.
a:Int?a //此时是nila12 //此时是(Some 12)a! //此时是12 通过!解包
- Optional binding is unpacked directly
var18iflet yourAge = age{ pringln("\(yourAge)") }
Base operator
var1var a = b
a530a + ba - ba * ba / b //此处除数不能为0,求余也不能为0a % bInt.max //整型的最大值Int.min //整型的最小值
- "+ +", "--" self-added self-reduction
varc=0c++c--c+=2
- Comparison operator (==,! =,>,<,===,!==)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Play Transfer swift--Study notes (continuous update)