How to unwrap double optionals?

后端 未结 5 665
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  星月不相逢
    2020-11-27 15:02

    Try

    var a:String?? = "1"
    print((a))
    if let b = a,c = b{
        print(c)
    }
    

    Screenshot of playground

    Also you can force unwrap,but it it is not secure

    let d = a!!
    

提交回复
热议问题