Swift: ++ is deprecated - replaced code does not work

I know that “++” will be removed in Swift 3, and it should be removed:

+ = 1

but in this code, when I change this value, I get an error:

override func viewDidLoad() {
    super.viewDidLoad()

    imageView.image = images[index++]
    animateImageView()
}

When I insert:

imageView.image = images[index += 1]

I get an error. How to change this code? This is the image transition code (if I need, I put the whole code), but everything works in Simulator, but still I would like to change it.

+4
source share
2 answers

Move += 1from the indexer, for example:

override func viewDidLoad() {
    super.viewDidLoad()
    imageView.image = images[index]
    index += 1
    animateImageView()
}
+2
source

As dasblinkenlight mentioned, the solution is to simply move the increment so that after you index the array.

, , postfix. ++index, index += 1 .

, . , , .

++ :

//++ declared as postfix operator before this.
func ++ (inout num: Int) -> Int {
  let temp = num
  num = num + 1
  return temp
}

+= , :

func += (inout lhs: Int, rhs: Int) {
  lhs = lhs + rhs
}

, ++ Int, , , += void ( ), , , Int .

+3
source

All Articles