1

I have had a problem with a video asset not being accessible from mainBundle. I am using XCode 7 and Swift 2.0. I wrote a very simple test app.

var objects = [String]()

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let fm = NSFileManager.defaultManager()
        let path = NSBundle.mainBundle().resourcePath!
        let items = try! fm.contentsOfDirectoryAtPath(path)

        for item in items {
                print ("item = \(item)")
                objects.append(item)
        }

    }

}

I have four media assets in my app: i) testVideo.m4v ii) benbeijing.mov iii) TestVideoCopy.m4v and iv) benbeijing2.mov.

When I run the program I get the following output.

item = Base.lproj
item = benbeijing.mov
item = benbeijing2.mov
item = Frameworks
item = Info.plist
item = mainBundleTests
item = PkgInfo

In other words 2 of the video media items are not listed.

I have played around with titles, suffixes, locations in the mainBundle folder but can't for the life of me figure out why these items can't be found. Any help would be much appreciated.

petegrif
  • 69
  • 1
  • 11

1 Answers1

1

I tried running exactly the same code that you're running. I am able to see that all the files present in my bundle gets printed.

But then, I am assuming you might have missed to add those files to target. This can also be a possible reason.

Can you confirm if you had added all the files that were added to bundle to corresponding target ?

To add the file to target

  • I am sorry but I'm not clear where it is that I 'add bundle to corresponding target'. I couldn't figure out how to translate the image you kindly linked for me. I checked the 'build phases' and interestingly the two missing files weren't included under 'copy bundle resources' but when I added them and rebuilt it still didn't solve the problem. – petegrif Oct 14 '15 at 19:16
  • When I say adding the file to target. I meant what ever target your running, the video files must be added to that target (for phone). How: 1. While adding files, please ensure to check the corresponding target. Did i make myself clear? – Sankar Narayanan Oct 15 '15 at 09:19