TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Project 11 Bookworm - DetailView Preview crashed

Forums > 100 Days of SwiftUI

Hello,

I have adopted the code suggested by Paul for the preview 1:1

struct DetailView_Previews: PreviewProvider {
    static let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)

    static var previews: some View {

        let book = Book(context: moc)
        book.title = "Test book"
        book.author = "Test author"
        book.genre = "Fantasy"
        book.rating = 4
        book.review = "This was a great book; I really enjoyed it."

        return NavigationView {
            DetailView(book: book)
        }
    }
}

However, the DetailView Preview always crashed for me ...?? Have I forgotten something or done something wrong? I have searched the forum for solutions, I also came across a good tip from @Obelix about the free e-book from bigmountainstudio, however, the solution suggested there to MockData has also brought me no success.

Does anyone have an idea what I can do here so that the preview does not crash ... except to do without the preview ;-)

2      

Sorry, I just searched the forum again, no idea why I didn't see it before, but @metropol's suggested solution in https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-56-bookworm-preview-crashes-when-using-moc/19940 works for me too.

Sorry for the xtra topic and confusion.

2      

In my case the exact same code as Paul suggested works. Most probably the issue might be in DetailView itself.

2      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.