iOS Database Module 3 Challenge 1 Quotes App

Hi,
unfortunately, the link within the Quotes App Challenge to the discussion thread is dead/not found.
I’m currently troubleshooting, why my QuotesListView doesn’t display the quotes.
Any hints?
TiA
BR David

QuotesListView:

import SwiftUI
import SwiftData

struct QuotesListView: View {
    
    @Environment(\.modelContext) private var context
    @Query private var quotes: [Quote]
    
    var body: some View {
        NavigationStack {
            List(quotes) { q in
                NavigationLink {
                    AddEditQuoteView(quote: q)
                } label: {
                    QuoteDetailView(quote: q)
                }
                .listRowSeparator(.hidden)
                .listRowBackground(Color.clear)
                
            }
            .listStyle(.plain)
            .navigationTitle("Quotes")
            .toolbar {
                // Trailing button with
                // view modifiers
                ToolbarItem(placement: .topBarTrailing) {
                    NavigationLink(destination: AddEditQuoteView(quote: nil), label: {
                        Image(systemName: "plus")
                    })
                }
            }
        }
    }
}

QuoteDetailView

import SwiftUI

struct QuoteDetailView: View {
    
    var quote : Quote
    
    var body: some View {
        ZStack {
            RoundedRectangle(cornerRadius: 15)
                .frame(height: 200)
            
            VStack {
                HStack {
                    Text(quote.text)
                        .foregroundStyle(.white)
                        .font(.title)
                    
                    Spacer()
                }
                Spacer()
                HStack {
                    Spacer()
                    Text("- \(quote.author)")
                        .foregroundStyle(.white)
                        .font(.title2)
                }
            }
            .padding()
            .frame(height: 200)
            .foregroundStyle(.white)
        }
    }
}

Found the issue. I forgot of the modelContainer in the app entry.
.modelContainer(for: Quote.self)

@DavidRaff

Hi David,

Welcome to the community.

Well done solving that yourself. I was going to ask you to provide the other swift files that go towards making up the project to see if there was something obvious.

1 Like