BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Project 11 Bookworm - DetailView Preview crashed

Forums > 100 Days of SwiftUI


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" = "Test author"
        book.genre = "Fantasy"
        book.rating = 4 = "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 ;-)


Sorry, I just searched the forum again, no idea why I didn't see it before, but @metropol's suggested solution in works for me too.

Sorry for the xtra topic and confusion.


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


Hacking with Swift is sponsored by Guardsquare

SPONSORED AppSweep by Guardsquare helps developers automate the mobile app security testing process with fast, free scans. By using AppSweep’s actionable recommendations, developers can improve the security posture of their apps in accordance with security standards like OWASP.

Learn more

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

Reply to this topic…

You need to create an account or log in to reply.

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.