我接收到錯誤在我的TimeView控制器就行 'EXC_BAD_ACCESS(代碼= 2,地址= 0x16fcbbfec)'接收 'EXC_BAD_ACCESS代碼= 2' 在一個OBJ-C至夫特轉換
var soundEffects = SoundEffects()
和我不知道爲什麼會發生這種情況...
我已經提供了我的源代碼的鏈接,供任何願意看一看並幫助我的人。謝謝!
https://github.com/JohnnyH1012/HRC
相關代碼
import UIKit
import AVFoundation
class SoundEffects: NSObject, AVAudioPlayerDelegate {
var soundEffects = SoundEffects()
var player = AVAudioPlayer()
var storage = SettingsStorage()
var enabled:Bool = false
var newValue:Bool = true
var tabata: Tabata!
var theme: Theme!
func registerSoundEffects() {
soundEffects = SoundEffects.new()
NSNotificationCenter.defaultCenter().addObserver(soundEffects, selector: "stateChanged:", name: StateChanged, object: nil)
NSNotificationCenter.defaultCenter().addObserver(soundEffects, selector: "prepareSignal:", name: PrepareSignal, object: nil)
var error:NSError?
var url: NSURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("beep_01", ofType: "mp3")!)!
player = AVAudioPlayer(contentsOfURL: url, error: &error)
player.numberOfLoops = 0
player.prepareToPlay()
enabled = storage.loadSoundEnabled()
}
func isEnabled() {
return enabled = true
}
func setEnabled() {
enabled = newValue
storage.saveSoundEnabled(newValue)
}
func stateChanged(notification: NSNotification) {
if enabled {
var tabata: Tabata! = notification.object! as! Tabata
switch tabata.getState() {
case .EXERCISE: fallthrough
case .RELAXATION:
player.play()
break
default:
break
}
}
}
func prepareSignal(notification:NSNotification) {
if enabled {
player.play()
}
}
}
是的,但如何將這個問題能解決? –
好吧,我需要你解釋你的意圖,讓一個類包含一個變量中自己的實例的引用。 – AnthonyM
我不完全確定,我從Github中取回了計時器項目,並試圖理解作者的工作。 –