0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Swift】Result of call to ‘map’ is unused という警告が出る

0
Posted at

現象

XcodeでSwiftUIの開発をしていて、”Result of call to ‘map’ is unused”という警告が出て、ビルドは成功するので別に放っておいてもいいけれど、どうしようかなと思った時のことです。
ざっくり下のような感じの状況です。

func sample() { 
    let items = ["test", "test2"]
    var sampleArray = []

    items.map{ sampleArray.append($0) }  // <- Result of call to 'map' is unused
}

環境

・Xcode26.2

解決策

mapの結果が使われていないことが原因で警告が出ているので、下記のようにアンダーバー"_"を使って明示的に結果を破棄することで解決できます。

let _ = items.map{ sampleArray.append($0) }  // mapの結果を明示的に破棄
0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?