NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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 Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try now

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.