Chapter 4 error

I’ve got an error message while running playground:
Fatal error: Unexpectedly found nil while unwrapping an Optional value: file N3DTransforms_Sources/Utility.swift, line 21

There is no Utility.swift in 04-3d-transforms folder.

1 Like

Apple changed the way playgrounds access Metal shaders in Xcode 12. You used to have to access it via the bundle, but it seems that we can now just use makeDefaultLibrary() as we do in an app.

So change the method in Utility.swift:

public func createLibrary() -> MTLLibrary {
  device.makeDefaultLibrary()!
}

Unfortunately as of Xcode 12.2, the playground will only work on Big Sur, as playgrounds now use Metal Shading Language v2.3, which is only available on Big Sur. Xcode 11 should work though.

(Also see: Chapter 2: SceneKit editor is blank)

6 Likes