Jake
Jake

Reputation: 13761

Swift Array Issues

I have this code:

let posState = positionState(pos)
if posState != .None {
    if posState == .Off {
        boardArray[pos.row][pos.column] == .On
    } else {
        boardArray[pos.row][pos.column] == .Off
    }
}

The issue I'm having is that when I attempt to change the value of an element in boardArray, nothing happens. Why does boardArray's element stay the same?

Upvotes: 0

Views: 47

Answers (2)

Anil Varghese
Anil Varghese

Reputation: 42977

Its not ==, use the assignment operator =

   boardArray[pos.row][pos.column] = .On

Upvotes: 0

iDhaval
iDhaval

Reputation: 3205

You are using == rather than = for assigning

let posState = positionState(pos)
   if posState != .None {
      if posState == .Off {
         boardArray[pos.row][pos.column] = .On
      } else {
         boardArray[pos.row][pos.column] = .Off
    }
}

Upvotes: 2

Related Questions