例如如上图所示,会提示
Value of optional type 'String?' must be unwrapped to a value of type 'String'
这是因为,??会将左边整个表达式都作为验证对象,
"当前年份-" + yearLabel.text
但是我只想判断yearLabel.text是否为空,所以,只要要加个括号接口,像这样:
print("当前年份-" + (yearLabel.text ?? "2022"))
例如如上图所示,会提示
Value of optional type 'String?' must be unwrapped to a value of type 'String'
这是因为,??会将左边整个表达式都作为验证对象,
"当前年份-" + yearLabel.text
但是我只想判断yearLabel.text是否为空,所以,只要要加个括号接口,像这样:
print("当前年份-" + (yearLabel.text ?? "2022"))