Hi! I am not entirely sure if Swift Packages (a Swift Playground is essentially a special type of Swift Package) support editing build phases like in Xcode projects.
When adding the folder to your playground (either by drag & drop or the plus button in the bottom left), wasn't it automatically placed within a "Resources" folder? It believe the USDZ needs to be placed within the generated Resources folder, not at the root of your playground.
Then, you can access it using Bundle.main.url (and perhaps also Bundle.main.path):
// make sure that "filename" doesn't contain the extension!
guard let url = Bundle.main.url(forResource: filename, withExtension:"usdz") else { fatalError("Couldn't find the USDZ file.") }
If you really need multiple Resources folders, a "hacky" thing you could do is to edit the Package.swift file. Control-click the Playground file in Finder and choose theShow package contents option, then open the Package.swift file and edit the target's resources:
targets: [
.executableTarget(
name: "AppModule",
path: ".",
resources: [
.process("Resources"),
.process("Second Folder") // your second folder
]
)
]
But make sure to pay attention to the warning that you may have at the beginning of this file:
// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.
This file's contents may change when you edit other settings such as the App Icon from within Xcode. From my testings the resources folders seem to stay intact, but it's good to keep the warning in mind. Thus, the best way would be to simply use the provided "Resources" folder.
Topic:
App & System Services
SubTopic:
Core OS
Tags: