2016-11-15 74 views
-3

我在这个问题上从一个星期开始工作,试图用新的代码替换大多数代码,并且它仍然崩溃,下面有错误。 Google搜索了一周,研究了几乎所有主题。最后来到这里寻求帮助。EXC_BAD_ACCESS主题1。代码如下。 swift 3

0x10006dc50 < +84>:bl 0x100072fcc;符号存根 for:objc_msgSend 0x10006dc54 < +88>:ldr x0,[sp,#8] 0x10006dc58 < +92>:bl 0x100072fe4;符号存根:objc_release 0x10006dc5c < 96>:ADRP X8,11

EXC_BAD_ACCESS线程1。下面的代码为 。

//--------------calmingseaplayer----------------- 
do { 
    let audioPath = Bundle.main.path(forResource: "calming", ofType: "wav") 
    try morningdewplayer = AVAudioPlayer(contentsOf:URL(fileURLWithPath: audioPath!)) 
} 
catch { //Error } 
+0

将代码发布到崩溃位置。坏访问意味着一个对象被释放,你试图使用它(或发送邮件到它) – ohr

+0

进口的UIKit 进口AVFoundation 级的音乐:UIViewController的{ VAR morningdewplayer = AVAudioPlayer() VAR birdplayer = AVAudioPlayer() VAR平静= AVAudioPlayer() VAR笛= AVAudioPlayer() 覆盖FUNC viewDidLoad中() 做{ 让audioPath = Bundle.main.path(forResource: “早晨”,ofType: “MP3”) 尝试morningdewplayer = AVAudioPlayer (contentsOf:URL(fileURLWithPath:audioPath!)) } catch { // Error } – Neeld

+1

用您的代码编辑您的原始文章,而不是在评论中:) – ohr

回答

0

部队去包裹可能不是你想要在这里做,验证与audioPath的网址是不是守着它无什么。

guard let audioPath = Bundle.main.path(forResource: "calming", ofType: "wav") else { print("Incorrect audio path"); return } 
guard let url = URL(fileURLWithPath: audioPath) else { print("URL is nil"); return } 
try morningdewplayer = AVAudioPlayer(contentsOf:url) 
+0

条件绑定的初始值设定项必须有可选类型,而不是'URL' – Neeld

+0

哦,对,你不需要第二个守卫,只需要第一个。 – ohr

相关问题