A.M.
A.M.

Reputation: 47

Swift Default Overload Unavailable - SCNReferenceNode(named: ) is not found

I am relatively new to Xcode.

Wondering how two files, with identical code can yield two very different build results. The first is downloaded from Apple's "Creating Face Based AR Experiences" sample code and the second is an implementation for my project. I've tried everything I can think of; rebuilding, cleaning, reinstalling, rebooting.... Even copied the exact code over from Apple's sample (as shown) and still fails. Seems to be an error that is keeping SCNReferenceNode from working properly in my project (to the right). Both files were working perfectly earlier. I have tried replacing code with SCNReferenceNode(url: ) combined with Bundle.main.url(forResource: withExtension: ) and displays the same error. It could be related; when loading project there seemed to be some missing documents (highlighted in red in Xcode) although they are in the physical files themselves. I have included a screenshot of the side by side comparison; as you can see, identical yet still an error. Any ideas on what could be causing this?

Screenshot:This is a side by side comparison of the Apple sample code and my code - now the same..

Upvotes: 1

Views: 489

Answers (1)

James P
James P

Reputation: 4836

If you take a look in the Utilites.swift file Apple have added an extension to SCNReferenceNode that adds a convenience init function.

extension SCNReferenceNode {
    convenience init(named resourceName: String, loadImmediately: Bool = true) {
        let url = Bundle.main.url(forResource: resourceName, withExtension: "scn", subdirectory: "Models.scnassets")!
        self.init(url: url)!
        if loadImmediately {
            self.load()
        }
    }
}

Upvotes: 2

Related Questions