我有以下代碼我想轉換爲Swift 3,並得到這個奇怪的錯誤「無法將類型Bool的值轉換爲預期的參數類型Int」。當我擺脫「++」時,問題就出現了。我也鏈接到我想完全轉換的堆棧溢出問題。謝謝!下面是前面的代碼,我試圖轉換爲代碼:如何轉換++或 - 在Swift 3中?
前面的代碼
func previousTrack() {
if currentTrack-- < 0 {
currentTrack = (playerItems.count - 1) < 0 ? 0 : (playerItems.count - 1)
} else {
currentTrack--
}
playTrack()
}
變換代碼
@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
編輯:
@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()
}
花費額外的線,第一減量比檢查<0 – vadian
那會是我的建議也是 –
你爲什麼用'+ ='替換舊的'--'?爲什麼不用' - ='? – rmaddy