我正在尝试制作一个有声音的应用程序。在向Xcode中的应用程序添加声音之前,我曾问过一个问题,但是每次我运行该应用程序时,控制台都会引发此错误,MagicSound.wav does not exist in main bundle在编写代码时,我基本上告诉程序使应用程序崩溃并编写,MagicSound.wav does not exist in main bundle如果它是真的, 。我的问题是如何在Xcode中将文件(特别是声音文件)添加到包中。我一直认为将文件放入资产与将其放入捆绑包是一样的。
这是我的代码,
`导入UIKit导入AVFoundation
类ViewController:UIViewController {
var magicSound: AVAudioPlayer = AVAudioPlayer()
@IBOutlet var Answer: UILabel!
var AnswerArray = ["Yes", "No", "Maybe", "Try Again", "Not Now", "No Doubt", "Yes Indeed", "Of course", "Definetley Not"]
var chosenAnswer = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if let magicFile = Bundle.main.path(forResource: "MagicSound", ofType: "wav") { …Run Code Online (Sandbox Code Playgroud)