Errors in chapter when I insert the export code

when I insert below code in playground …following chapter 2 I got following error:

atal error: Error The operation couldn’t be completed. (Foundation._GenericObjCError error 0.): file __lldb_expr_23/Render and Export 3D Model.xcplaygroundpage, line 32

Playground execution failed:

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).

Can any one help me to resolve this error?

// begin export code

let asset = MDLAsset()

asset.add(mdlMesh)

let fileExtension = “obj”

guard MDLAsset.canExportFileExtension(fileExtension) else {

fatalError(“Can’t export a .(fileExtension) format”)

}

do {

let url = playgroundSharedDataDirectory.appendingPathComponent(“primitive.(fileExtension)”)

try asset.export(to: url)

} catch {

fatalError(“Error (error.localizedDescription)”)

}

// end export code

I go

This doesn’t seem to relate at all to the Push Notifications book.

this is from the Metal book

cc @hcrogman

Yes, this came from the book Metal by tutorials

Hi @hcrogman - did you create a directory in Documents called Shared Playground Data?

Playgrounds needs this directory to be able to export files.

Hello Caroline, thank you that works.

1 Like