Hello Chris, I have spent considerable amount of time trying to get this program to work. Can you assist please.
//
// Card.swift
// Quotes
//
// Created by Jaime Fernandes on 12/11/21.
//
import SwiftUI
struct Card: View {
var author:Author
var body: some View {
ZStack {
//Background Image
Image(author.image)
.resizable()
.aspectRatio(contentMode: .fill)
.cornerRadius(15)
//Quote if there is at least 1
if author.quotes.count > 0 {
Text(author.quotes[0])
.font(.largeTitle)
.fontWeight(.bold)
}
// Name
Text("- " + author.name)
}
.padding([.top, .leading], 20.0)
.shadow(color: .black, radius: 10, x: 2, y: 2)
}
.foregroundColor(Color.white)
.frame(width: .none, height: 400, alignment: .centre)
.clipped()
.cornerRadius(15)
.padding([.leading, .trailing])
}
struct Card_Previews: PreviewProvider {
static var previews: some View {
Card(author: Author.testData())
}
}
//
// ContentView.swift
// Quotes
//
// Created by Jaime Fernandes on 12/11/21.
//
import SwiftUI
struct ContentView: View {
@ObservedObject var model = AuthorModel()
var body: some View {
//NavigationView to go into detailview
NavigationView {
ScrollView {
// VStack to group all the cards
VStack(alignment: .leading, spacing: 20) {
//Card for each author
ForEach(model.authors) { a in
//Link to detail view
NavigationLink(
destination: DetailView(author: a),
label: {
//Each author card in the scrollview
Card(author: a)
})
}
}
}
.navigationBarTitle("Authors")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
//
// DetailView.swift
// Quotes
//
// Created by Jaime Fernandes on 12/11/21.
//
import SwiftUI
import AVKit
struct DetailView: View {
var author: Author
var body: some View {
//if no mediation set, can't display detail
VStack(alignment: .leading, spacing: 20.0) {
//Author name
Text(author.name)
.font(.largeTitle)
.fontWeight(.bold)
// Quotes
ForEach (author.quotes, id: \.self) { quote in Text(quote)
}
Spacer()
}.padding
}
}
struct DetailView_Previews: PreviewProvider {
static var previews: some View {
DetailView(author: Author.testData())
}
}