class Sound {
var soundID: SystemSoundID = 0
var isPlaying = false
func playSound() {
let soundURL = ...
AudioServicesCreateSystemSoundID(soundURL, &soundID)
AudioServicesPlaySystemSound(soundID)
self.isPlaying = true
AudioServicesAddSystemSoundCompletion(soundID, nil, nil, { soundID, inClientData in
let me = unsafeBitCast(inClientData, Sound.self)
me.audioServicesPlaySystemSoundCompleted(soundID) -> Error: Thread 1: EXEC_BAD_ACCESS
}, UnsafeMutablePointer(unsafeAddressOf(self)))
}
func audioServicesPlaySystemSoundCompleted(soundID: SystemSoundID) {
print("Completion")
isPlaying = false
AudioServicesRemoveSystemSoundCompletion(soundID)
AudioServicesDisposeSystemSoundID(soundID)
}
}
Error: Thread 1: EXEC_BAD_ACCESS (code = 2, address = xxx)
I really have no idea why I got this error. I debugged the code and the address of me
is exactly same as the self
passed in.