gpt4 book ai didi

ios - xcode9 swift4 fatal error : Unexpectedly found nil while unwrapping an Optional value

转载 作者:行者123 更新时间:2023-11-30 11:31:43 32 4
gpt4 key购买 nike

我尝试在应用程序启动时播放 mp3 文件(5 秒),但不断收到错误消息:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

import UIKit
import AudioToolbox

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

//create SystemSoundID
var soundID:SystemSoundID = 0
let path = Bundle.main.path(forResource: "iPhone100Voice", ofType: "mp3")
let baseURL = NSURL(fileURLWithPath: path!)
AudioServicesCreateSystemSoundID(baseURL, &soundID)
//play
AudioServicesPlaySystemSound(soundID)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

谁能解释一下为什么以及如何解决这个问题?

最佳答案

检查以下几点,所有条件都必须为真:

  • 该文件是否在项目导航器中?
  • 是否在文件检查器中选中了目标成员资格复选框(要使其选中文件并按⌥⌘1)
  • 文件名拼写是否正确(iPhone100Voice.mp3)?

关于ios - xcode9 swift4 fatal error : Unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50187940/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com