Group Group Group Group Group Group Group Group Group

Chapter 2: 3D Models. Export asset

let asset = MDLAsset()

/// 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)")!
    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:


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:

It was confused, but I also found the correct answer.

I enjoy reading books. Thank you so much for making a book!

I’m glad you found the correct answer and are enjoying the book :smiley:!