I couldn't get my the below struct to initialise until I moved it into the body of the View. Can someone explain that to me please? Thanks!
This didn't work:
struct ContentView: View {
var sampleText = "This is sample text"
var booksArray = ["Book 1", "Book 2", "Book 3"]
let aBook = Book(passage: sampleText, books: booksArray)
var body: some View {
ScrollView(.vertical, showsIndicators: false, content: {
VStack {
Text(aBook.passage)
.frame(width: 350, height: .infinity, alignment: .center)
.kerning(1)
}
})
}
}
But this did work:
struct ContentView: View {
var sampleText = "This is sample text"
var booksArray = ["Book 1", "Book 2", "Book 3"]
var body: some View {
let aBook = Book(passage: sampleText, books: booksArray)
ScrollView(.vertical, showsIndicators: false, content: {
VStack {
Text(aBook.passage)
.frame(width: 350, height: .infinity, alignment: .center)
.kerning(1)
}
})
}
}