Group Group Group Group Group Group Group Group Group

Chapter 2: 3D Models. Export asset

let asset = MDLAsset()
asset.add(mdlMesh)

/// 2
let fileExtension = "obj"
guard MDLAsset.canExportFileExtension(fileExtension) else {
    fatalError("Can't export a .\(fileExtension)")
}

/// 3
do {
    let url = playgroundSharedDataDirectory.appendingPathComponent("primitive.\(fileExtension)")
//    let url = URL(string: "/Users/thomascurley/Documents/primitive.\(fileExtension)")!
    print(url)
    try asset.export(to: url)
}
catch {
    fatalError("Error \(error.localizedDescription)")
}

Hello, I’ve copied this code from the book, however, when I try to execute this I get an exception thrown:

Fatal error: Error The operation couldn’t be completed. (Foundation._GenericObjCError error 0.): file Chapter1.playground, line 40

I have made a directory in
~/Documents/Shared Playground Data

However, when I print the URL the location isn’t the same:

file:///Users/thomascurley/Library/Developer/XCPGDevices/D9EB2BCE-ABB8-4571-8B6B-7ACCC0BE32EE/data/Containers/Data/Application/73982C04-BFA7-4898-A34F-9228D722B767/Documents/Shared%20Playground%20Data/primitive.obj

How do I fix this,

many thanks

I’m really enjoying this book!!!

@tomus85 I’m happy to hear that you’re enjoying the book!

Did you create a macOS playground? Looking at your URL, it looks as if you may have created an iOS playground.

Try creating a blank macOS playground and copy/paste your code into that and try it

1 Like

@caroline, ahh many thanks, that would explain it. :roll_eyes: