###前提・実現したいこと
SwiftでDictionaryを宣言し、ターミナルで出力すると
warningが発生します。
これは何が問題となっているのでしょうか。
###発生している問題・エラーメッセージ
test.swift:7:7: warning: expression implicitly coerced from 'Int?' to Any
print(numberOfTires["車"])
test.swift:7:20: note: provide a default value to avoid this warning
print(numberOfTires["車"])
test.swift:7:20: note: force-unwrap the value to avoid this warning
print(numberOfTires["車"])
test.swift:7:20: note: explicitly cast to Any with 'as Any' to silence this warning
print(numberOfTires["車"])
Optional(4)
###該当のソースコード
var numberOfTires:[String: Int] = ["車":4,"バイク":2,"船":0] print(numberOfTires["車"]) ###version Swift version 3.0.2
Swiftのバージョンを教えて下さい。あと、コードやエラーメッセージはテキストで書いて下さい。
回答1件
あなたの回答
tips
プレビュー