Access the files/folders in the Assets folder for TVOS programmatically
<p>I am working on a TVOS 10 project with Swift 3.0 and I am trying to access the files in the Assets folder from the controller.</p>

<p>I have this array: </p>

<pre><code>var posters: [String] = ["image1", "image2", "image3","image4", "image5"]
</code></pre>

<p>But I want to populate this array programmatically. So if i change the files in the assets, the content of the array should change.</p>

<p>Because later I do this:</p>

<pre><code>//currentImage is an ImageView in storyboard
 currentImage.image = UIImage(named: posters[currentPoster])
</code></pre>

<p>This is the hierarchy of my files.<a href="https://i.stack.imgur.com/Gf5LQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gf5LQ.png" alt="enter image description here"></a></p>

<p>This is what I have tried but it does not give me what I want.</p>

<pre><code>if let resourcePath = Bundle.main().resourcePath {
        print(resourcePath)
        do {
            let temp = try FileManager.default().contentsOfDirectory(atPath: resourcePath)
            print(temp)
            let assetsPath = resourcePath + "/" + temp[6]
            let temp2 = try FileManager.default().contentsOfDirectory(atPath: assetsPath)
            print (temp2)
        }
        catch let error as NSError {
            print(error)
        }
    }
</code></pre>

<p>Output:</p>

<p>/var/containers/Bundle/Application/9AECCDB0-DD5F-4377-9237-6E7DA1E14A39/PosterAppTV.app</p>

<p>["Assets.car", "Base.lproj", "Frameworks", "Info.plist", "META-INF", "PkgInfo", "PosterAppTV", "_CodeSignature", "embedded.mobileprovision", "libswiftRemoteMirror.dylib"]</p>

<p>Error Domain=NSCocoaErrorDomain Code=256 "The file “PosterAppTV” couldn’t be opened." UserInfo={NSFilePath=/var/containers/Bundle/Application/9AECCDB0-DD5F-4377-9237-6E7DA1E14A39/PosterAppTV.app/PosterAppTV, NSUserStringVariant=(
    Folder
), NSUnderlyingError=0x1740524e0 {Error Domain=NSPOSIXErrorDomain Code=20 "Not a directory"}}</p>

<p>Any help how to get a list of names of the files in the Assets/Posters folder?
Also, if this may not be possible, are there other ways to store some pictures into a folder and then access the names of those files programmatically?</p>