How to print a string from plist without “Optional”?

前端 未结 6 1788
遥遥无期
遥遥无期 2020-12-10 01:46

I load a value from a dictionary in a plist but when I print it to the console, it prints: Optional(Monday Title) rather than just \"Monday Title\".

How can I get ri

6条回答
  •  鱼传尺愫
    2020-12-10 02:38

    I'm not sure what the proper process is for linking to other answers, but my answer to a similar question applies here as well.

    Valentin's answer works well enough for optionals of type String?, but won't work if you want to do something like:

    let i? = 88
    print("The value of i is: \(i ?? "nil")")  // Compiler error
    

提交回复
热议问题