0
0

More than 5 years have passed since last update.

本日のエラー

Last updated at Posted at 2019-02-26

String interpolation produces a debug description for an optional value; did you mean to make this explicit?

Google翻訳
「文字列補間は、オプションの値に対するデバッグ記述を生成します。これを明確にするつもりでしたか?」

原因

Optional型の文字列をunwrapせず直接出力しようとした。

解決方法

インターンで扱ったコードを簡略化したものです。

var text:String? = nil
text = "Internship"
print("\(text ?? "text is nil")")

こんな感じでやったと思う。

あと使わなかったけどこれ。

let text: String? = nil
text = "Internship"

if let text = text {
    print("\(text)")
}
else {
    print("nil")
}       

強制アンラップは基本使わないと以前教わりました。
エラーもメモだけじゃなくてQiitaにもあげていこうと思います!
以上です!

3月から就活の合間合間で100DaysOfCodeやってみようかなと思います!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0