Skip to content

Instantly share code, notes, and snippets.

@mhijack
Created June 13, 2021 00:15
Show Gist options
  • Save mhijack/fa6af1c0ac6b79404a8a40281558d958 to your computer and use it in GitHub Desktop.
Save mhijack/fa6af1c0ac6b79404a8a40281558d958 to your computer and use it in GitHub Desktop.
struct BookList: View {
@ObservedObject var store = BookStore() // <- Change to @StateObject or create this else where to solve the issue
var body: some View {
List {
ForEach(store.books, id: \.name) {
Text($0.name)
}
}
}
}
class BookStore: ObservableObject {
@Published var books: [Book] = [Book(name: "The "Great Influenza)]
}
struct ContentView: View {
var body: some View {
NavigationView {
BookList()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment