我认为这是可能的,但似乎无法让它发挥作用。我确定我只是在装傻。我试图以
的形式输出格式化地址"one, two, three"
来自一组可选组件(一、二、三)。如果“二”为零,则输出为
“一、三”
let one: String?
let two: String?
let three: String?
one = "one"
two = nil
three = "three"
if let one = one,
two = two,
three = three {
print("\(one),\(two),\(three)")
}
最佳答案
我不知道你为什么需要这个,但接受它 =)
if let _ = one ?? two ?? three {
print("\(one),\(two),\(three)")
}
关于快速展开多个可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38014138/