LoginSignup
1
0

More than 1 year has passed since last update.

【メモ】Swiftの"_" これの意味は?(アンダーバー,アンダースコア)

Posted at

最近SwiftでiOSアプリ作りにハマっています。

使用PC: MacBook Air (11-inch, Mid 2013)
OSバージョン: 11.4
Xcodeバージョン: 12.5

sample.swift
let scene = GameScene(size:CGSize(width: 750, height: 1334))

こちらを書こうとした際にXcodeからこのような警告文が。
スクリーンショット 2021-06-11 15.10.16.png

Initialization of immutable value 'scene' was never used; consider replacing with assignment to '_' or removing it

Replace 'let scene' with '_'

Replace 'let scene' with '_'と暗示され、Fixボタンを押してみると、

sample.swift
_ = GameScene(size:CGSize(width: 750, height: 1334))

アンダースコアの意味は、メソッドから戻り値は返ってくるが、使用しない。という意味だそうです。

引数が明確な場合はアンダースコアを入れてあげると楽になります。

1
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
1
0