This question already has an answer here:
I have the following code I am trying to convert to Swift 3 and am getting this weird error "Cannot convert value of type Bool to expected argument type Int". The issue arises when I get rid of the "++". I am also linking to the stack overflow question I want to fully convert. Thanks! Here is the previous code and the code I tried to convert to:
Previous code
func previousTrack() {
if currentTrack-- < 0 {
currentTrack = (playerItems.count - 1) < 0 ? 0 : (playerItems.count - 1)
} else {
currentTrack--
}
playTrack()
}
Converted code
@IBAction func didTapPreviousButton(_ sender: UIButton) {
if currentTrack += 1 < 0 { // Issue occurs here
currentTrack = (urlPlayerItems.count - 1) < 0 ? 0 : (urlPlayerItems.count - 1)
} else {
currentTrack -= 1
}
playTrack()
}
Original question I want to convert to Swift 3
EDIT:
@IBAction func didTapPreviousButton(_ sender: UIButton) {
if (currentTrack - 1) <= 0 {
currentTrack = (urlPlayerItems.count - 1) < 0 ? 0 : (urlPlayerItems.count - 1)
} else {
currentTrack -= 1
}
playTrack()
}
@IBAction func didTapNextButton(_ sender: UIButton) {
if (currentTrack + 1) >= urlPlayerItems.count {
currentTrack = 0
} else {
currentTrack += 1
}
playTrack()
}
What you want IMHO
Correct replacing of POSTFIX as you have it (useless)