let score: Double? = 100

if score == nil {

print("no score!")

}else{

print("Score:\(score)")

}

⚠️String interpolation produces a debug description for an optional value; did you mean to make this explicit?

处理一:Use 'String(describing:)' to silence this warning

let score: Double? = 100

if score == nil {

print("no score!")

}else{

print("Score:\(String(describing: score))")

}

处理二:提供默认值

let score: Double? = 100

if score == nil {

print("no score!")

}else{

print("Score:\(score ?? 0)")

}

处理三:解包

let score: Double? = 100

if score == nil {

print("no score!")

}else{

print("Score:\(score!)")

}

精彩链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。