Copy resources to App Bundle in Swift Playground

30 Views Asked by At

I am attempting to load a USDZ file into a QuickLook view from within a Swift Playground. This USDZ file is in the root of my playground. Unfortunately, my project needs to be a playground so I can't make a normal Xcode project.

I'm using the latest (to my knowledge) stable release of Xcode (15.1).

When I attempt to access the file with the following code:

guard let path = Bundle.main.path(forResource: fileName, ofType: "usdz") else { fatalError("Couldn't find the USDZ file.") }

the fatalError is thrown as the resource isn't copied over into the app bundle at build-time.

In a normal Xcode project, according to this StackOverflow question, I can use the Copy Bundle Resources build phase to copy my resource over, however, to my knowledge, build phases cannot be edited from within a Swift Playground. I can't find any option for Build Phases in the default target.

How can I ensure that resources are copied over to the App Bundle at build-time in a Swift Playground?

If this is not possible - what are the options for shipping the file with my app and accessing it at runtime from within a playground?

0

There are 0 best solutions below