swift - What's the point of if let statements? -


i've read swift docs on optional binding it's incomprehensible me @ level of knowledge (and/or intelligence).

what's difference between:

var number:int? = 1 if let num = number {     print("number \(number!)" } else {     print("it must nil") } 

and

var number:int? = 1 if number==nil {     print("it must nil") } else {     print("number \(number!)" } 

as far can tell, these work same, , @ least me second 1 more readable. , wouldn't ordinarily care this, if let prominent in basic tutorials it's useful, i'd know why.

suppose had 2 optional values , b classic syntax

if != nil {     if a?.b != nil {         here access a.b.blah      } } 

new syntax

if let blah=a?.b?.blah {    use blah ... } 

it's shorter,more readable , more flexible


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -