zl程序教程

您现在的位置是:首页 >  其他

当前栏目

SwiftUI 基础之??双问号是什么运算符

基础 什么 SwiftUI 运算符 问号
2023-09-11 14:18:48 时间

SwiftUI 基础之??双问号是什么运算符

实战需求

SwiftUI特殊的数据流程让单问号?成为最常用的条件语句,那双问号??有什么作用

使用用途

The nil-coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil. The expression a is always of an optional type. The expression b must match the type that is stored inside a.

双问号是nil-coalescing运算符,如果a为nil,则让a=b。

let val = something["something"] as? String ?? nil

技术交流

QQ:3365059189
SwiftUI技术交流QQ群:518696470