title: How to add sound files to your bundle in Xcode?
body: <p>I am trying to make an application with sound. I have asked a question before how to add sound to an app in Xcode but every time I run the app, the console throws this error, <code>MagicSound.wav does not exist in main bundle</code> when writing my code I basically told the program to crash the application and write <code>MagicSound.wav does not exist in main bundle</code> if it comes to be true. My question is how do you add a file (specifically
  a sound file) to your bundle in Xcode. I always assumed putting a file in your assets is the same thing as putting it in your bundle.</p>
  <p>Here is my code,</p>
  <pre><code>import UIKit
  import AVFoundation
  
  class ViewController: UIViewController {
      
      
      var magicSound: AVAudioPlayer = AVAudioPlayer()
      
  
      @IBOutlet var Answer: UILabel!
      
      var AnswerArray = [&quot;Yes&quot;, &quot;No&quot;, &quot;Maybe&quot;, &quot;Try Again&quot;, &quot;Not Now&quot;, &quot;No Doubt&quot;, &quot;Yes Indeed&quot;, &quot;Of course&quot;, &quot;Definetley Not&quot;]
      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: &quot;MagicSound&quot;, ofType: &quot;wav&quot;) {
              _ = try? AVAudioPlayer(contentsOf: URL (fileURLWithPath: magicFile))
          }
          else {
              print( &quot;MagicSound.wav does not exist in main bundle&quot; )
          }
          
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
          
          if event?.subtype == motion {
              printAnswer()
              randomAnswer()
              animation()
              showingAnswerAnimation()
              magicSound.play()
          }
          
      }
  </code></pre>
  <p>If anybody could help that would be great!</p>
  <p>Thanks.</p>