Your Second iOS & SwiftUI App

Nov 4 2021 Swift 5.5, iOS 15, Xcode 13

Part 3: Managing Rows

22. Challenge: New Book Sheet

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions

See course reviews

See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 21. ForEach Next episode: 23. Environment

This video was last updated on Nov 4 2021

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

So! You’ve got a view that says “Add New Book”! Alas, it doesn’t actually do that. Yet!

@Published var 
@Published var 
class Book: ObservableObject {
  @Published var title: String
  @Published var author: String
  @Published var microReview: String
struct NewBookView: View {
  var book = Book(title: "", author: "")

  var body: some View {
@ObservedObject var book = Book(title: "", author: "")
  var body: some View {
    VStack {
      
    }
  }
    VStack {
      TextField("Title", text: $book.title)
    }
      TextField("Title", text: $book.title)
      TextField("Author", text: $book.author)
    }
    })
    .padding()
  }
      }

      ReviewAndImageStack()

      Spacer()
      }

      ReviewAndImageStack()
    }
        updateButton
      }

      Spacer()
    }
      ReviewAndImageStack()
    }
    .padding()
  }
}
      Spacer()
    }
    .sheet(isPresented: $showingImagePicker) {
      PHPickerViewController.View(image: $image)
    }
    .confirmationDialog(isPresented: $showingAlert) {
    }
  }
}
  @Binding var image: UIImage?

  var body: some View {
struct ReviewAndImageStack: View {
  @State var showingImagePicker = false
  @State var showingDialog = false

  var body: some View {
struct ReviewAndImageStack: View {
  @ObservedObject var book: Book
  @Binding var image: UIImage?
  @State var showingImagePicker = false
ReviewAndImageStack(book: book, image: $image)
/// THE SOFTWARE.

import class PhotosUI.PHPickerViewController
import SwiftUI
ReviewAndImageStack(book: .init(), image: .constant(nil)
    ReviewAndImageStack(book: .init(), image: .constant(nil))
      .padding(.horizontal)
  }
      .padding(.horizontal)
      .previewedInAllColorSchemes
  }
  @ObservedObject var book = Book(title: "", author: "")
  @State var image: Image? = nil

  var body: some View {
      TextField("Author", text: $book.author)
      ReviewAndImageStack(book: book, image: $image)
    })
VStack(spacing: 24, content: {
struct ContentView: View {
  @State var addingNewBook = false
  @State var library = Library()
        Button {
          addingNewBook = true
        } label: {
        .padding(.vertical, 8)
        .sheet(isPresented: /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Is Presented@*/.constant(false)/*@END_MENU_TOKEN@*/, content: {
          /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Content@*/Text("Sheet Content")/*@END_MENU_TOKEN@*/
        })

        ForEach(library.sortedBooks) { book in
.sheet(isPresented: $addingNewBook, content: {
        .sheet(
          isPresented: $addingNewBook,
          content: NewBookView.init
        )

        ForEach(library.sortedBooks) { book in