Get Reference to SceneKit Catalog Swift

955 views ios

I must be missing something simple - I'm trying to iterate through the files in an .scnassets folder but can't seem to get a reference to the folder/catalog.

Here's the organizer:

enter image description here

Models.scnassets contains one file. I tried this:

let fileManager = FileManager.default
let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask)
let docsURL = urls.first
let assetFolderPath = docsURL?.appendingPathComponent("Models.scnassets").path

And I tried this and several other variants:

let modelPathString = "ARAds/Models.scnassets"

Then I attempted to count the files with both of the above paths:

    do {
        let modelPathDirectoryFiles = try fileManager.contentsOfDirectory(atPath: assetFolderPath!)
        //or modelPathString
    } catch {
        print("error getting list of files")

I get the error message in all cases. I assume there must be some special way to get a reference to a SceneKit Catalog but I have not been able to find that in the Apple docs nor SO. Any guidance would be appreciated. iOS 11.4 Xcode 10.0

answered question

1 Answer


Looking at your code, the first thing I see, is that you are referencing the Documents Directory which isn't actually where your folder is.

The Documents Directory is a folder on your actual device where you might save user data or other files which can be accessed at a latter date (for example via iTunes Sharing).

If you move your Models.scnassets folder under the yellow ArAds folder you should be able to access your content like so:

let myModelToLocate = SCNScene(named: "Models.scnassets/Phone_01.scn")

Hope it helps...

posted this

Have an answer?


Please login first before posting an answer.