Subscribed unsubscribe Subscribe Subscribe

Mobile App Dev Diary

Android (Java, Kotlin), iOS (Swift), Xamarin (C#)

Swift 3.0 / unwrap optional values with if let statement

if let statement unwrap optional values.

var value : Int?
value = 5

if let value = value {
    //do something here
    print(String(value))
}

If you never use unwrapped optional value inside if let statement, you can use underscore with if let .

var value : Int?
value = 5

if let _ = value {
    //do something here
}
Remove all ads