How to unwrap double optionals?

后端 未结 5 666
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 13:59

How do you unwrap a string that is returned as:

(Optional(Optional \"blue\"))

var cityName = String()

if let cityAnno =         


        
5条回答
  •  猫巷女王i
    2020-11-27 15:00

    I must say the accepted answer is very good, and I pefer method 1 from from that answer. However I'd like to use different syntax, making it a little more readable:

    if case .some(.some(let value)) = a {
        print(value) // "hello\n"
    }
    

提交回复
热议问题