if let unwrappedOptional = postDict {

            print("The optional has a value! It's \(unwrappedOptional)")

        } else {

            print("The optional is nil!")

        }

if let 是个整体,也可以用 if var,这个if表示如果用let 或var声明变量成功即为true,跟生命的是什么值无关,即使是nil也行

,但是假如等号右边是为nil的optional类型的值,不会进行=号赋值,变量声明失败,即if判断为false



相关文章:

  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案