title: can not find image in subfolder in swift?
body: <p>I am building a very simple app for viewing pictures in a loop.<br>
  All pictures are stored in a subfolder in the project:
  <a href="https://i.stack.imgur.com/0XAFS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0XAFS.png" alt="project structure"></a></p>
  
  <p>And this is the code in ViewController:</p>
  
  <pre><code>    @IBOutlet var imageView: UIImageView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view.
  
          var images = [UIImage]()
  
          let items = Bundle.main.paths(forResourcesOfType: "jpg", inDirectory: "images")
          for item in items {
              let fileName = URL(string: item)?.lastPathComponent ?? "c1.jpg"
              let image = UIImage(named: fileName)!
              images.append(image)
          }
          imageView.image = UIImage.animatedImage(with: images, duration: Double(5*items.count))
      }
  }
  </code></pre>
  
  <p>This throws a runtime error on the line <code>let image = UIImage(named: fileName)!</code></p>
  
  <blockquote>
    <p>Fatal error: Unexpectedly found nil while unwrapping an Optional
    value: file</p>
  </blockquote>
  
  <p>The value of the fileName is "c1.jpg" which sounds right.</p>
  
  <p>And if my memory is still working, the same code was working on the simulator but had the runtime error on real device, and now it stop working on both. Not sure what is wrong? I can see the "images" folder is listed in the "Build Phases" so I think the images should be copied to the bundle?: 
  <a href="https://i.stack.imgur.com/92jig.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/92jig.png" alt="enter image description here"></a></p>