UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.