最佳答案
应该是currentAudioIndex++
(没有空格)。同:currentAudioIndex = (currentAudioIndex)%2
currentAudioIndex = (currentAudioIndex++)%2
// plus 1 to currentAudioIndex will be overrided by `currentAudioIndex =`.
// With (currentAudioIndex++)%2. E.g currentAudioIndex = 1
// 1. currentAudioIndex return 1 for the operator %. It's "1%2"
// 2. currentAudioIndex plus 1. currentAudioIndex == 2 now.
// 3. The operator % (1%2) return 1 for currentAudioIndex.
// 4. currentAudioIndex == 1 at the end.
但在你的情况下,我认为你想要这个
++currentAudioIndex
currentAudioIndex = currentAudioIndex + 1
currentAudioIndex = (currentAudioIndex)%2
关于ios - 为什么在swift中使用var++是错误的,但是更改为var + 1是正确的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33949366/