How to remove Optional from String Value Swift

后端 未结 3 749
不思量自难忘°
不思量自难忘° 2020-12-12 06:21

I\'d like to use a String value without the optional extension. I parse this data from firebase using the following code:

Database.database().reference(withP         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 07:09

    That's because your value is actually an optional. You could either do

    if let myString = laststring {
        print("Value is ", myString)
    }
    

    or provide a default value like so

    print("Value is ", laststring ?? "")
    

    (in this case the provided default value is "")

提交回复
热议问题