lundi 29 février 2016

if block being performed even when comparison values of Int are not equal (Swift)

func audioControllerDidFinishLoadingAudioForKey(key: Int) {

    print("current line position")
    print(scriptTableView.currentLinePosition)
    print("key")
    print(key)

    if scriptTableView.currentLinePosition == key && pausedPlayback == false {

        playbackRecordingWithKey(key)

        dispatch_async(dispatch_get_main_queue(), { () -> Void in

            if self.recordLines == true {
                self.setToolbarState(.RecordMode)
            } else {
                self.setToolbarState(.Playing)
            }

        })
    }
}

I am having some very strange behaviour with this if-statement.

The above function always performs the if block, even if the key is a different value to the currentLinePosition (both are Ints). The print output shows for example:

current line position
25
key
27
playbackRecordingWithKey

But "playbackRecordingWithKey" is still being called (there is a print function there as well)

Does anybody know why this might be happening or how to debug this? I'm a bit stumped here.

Aucun commentaire:

Enregistrer un commentaire