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?

More than 5 years have passed since last update.

Basic Operators - Assignment Operator

Last updated at Posted at 2017-02-22

代入演算子 Assignment operator, (a = b) は初期化、もしくは a の値を b に変更する機能を持つ。

let b = 10
var a = 5
a = b
// a の値は 現在 10

もし代入演算子の右側が複数の値を持つ タプル だった場合、その値をそれぞれ定数・変数に割り当てられる。

let (x, y) = (1, 2)
// x の値は 1 に、 y の値は 2 になる。

Swift の代入演算子は値を返さない。そのため、if文で2つの値が同じであることを条件としたい場合、下記はエラーとなる。

if x = y {
     // x = y は値を返さないのでエラーになる。正しくは x == y であるべき。
}
0
0
1

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?