# Swift 自學日誌 05

1.Int( )
`let possibleNumber = “123”let convertedNumber = Int(possibleNumber) //123//以Int(String) 將()內的數字轉為數字//若()裡面沒有沒有數字，則會出現nil`
2.if-let
`if let numberOne = Int("4"), let numberTwo = Int("42"), numberOne < numberTwo && numberTwo < 100 {    print("\(numberOne) < \(numberTwo) < 100")}//就會列印出"4 < 42 < 100"`
3.Ternary Conditional Operator (questions ? Anser1: Anser2)
`let aa = 40let bb = falselet cc = aa + (bb ? 10:20 )//cc 為 40 + 20 = 60//若 bb 為 true, 則 cc 為 40 + 10//ternary conditional operator 為 if- else 的簡化寫法`
4.??
`let defaultColorName = “red”var userDefinedColorName: String? // defaults to nilvar colorNameToUse = userDefinedColorName ?? defaultColorName// 意思就是:var c = a ?? b ，假設a為 nil 則 c=b，若a不為 nil 則 c=a`
5.Half-Open Range Operator

`let names=["Anna","Alex","Brian","Jack"]for i in 0..<names.count {     "person\(i+1) is \(names[i])"}// 0..<names.count 含的資訊很多，第一個就是0..<，從array 的第一個取到你想要的地方，就是half-open range，names.count就是去算共有幾個。//還蠻喜歡這個例子。`
6.!a

Like what you read? Give 陳冠宇 a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.