unwrapping multiple optionals in if statement

前端 未结 8 596
鱼传尺愫
鱼传尺愫 2020-11-28 07:38

I want to unwrap two optionals in one if statement, but the compiler complaints about an expected expression after operator at the password constant. What could be the reaso

8条回答
  •  独厮守ぢ
    2020-11-28 07:48

    The usage

    if let x = y {
    }
    

    is not equivalent to

    if (let x = y) { // this is actually not allowed
    }
    

    "if let" is effectively a two-word keyword, which is equivalent to

    if y != nil {
        let x = y!
        // rest of if let block
    }
    

提交回复
热议问题