import SwiftUI extension ShaderLibrary { // Important: Cache this instance. Initializing it is expensive. static let library: ShaderLibrary = { // Make sure to use the right binary based on the target #if targetEnvironment(simulator) let filename = "Shaders-iphonesimulator" #else let filename = "Shaders-iphoneos" #endif // Bundle.module is for Swift packages. Use whatever bundle contains your shader files. guard let url = Bundle.module.url(forResource: filename, withExtension: "metallib") else { fatalError("Missing shader library") } return ShaderLibrary(url: url) }() }