I want to use the qLeft in ContentView() in the struct Questions to pass in the value of questionLeft but how to do it. Any reply is much appreciated.
import SwiftUI
struct navModifier: ViewModifier {
func body(content: Content)-> some View {
content
.foregroundColor(.white)
.font(.custom("Helvetica",size: 40) .weight(.bold))
.shadow(color: .green, radius: 3, x: 2, y: 1)
.padding(EdgeInsets(top: 10, leading: 10, bottom: 0, trailing: 0))
}
}
extension View {
func navMod() -> some View {
self.modifier(navModifier())
}
}
struct ContentView: View {
@State private var noQ = ["1", "5", "10", "all"]
@State private var userQ = 0
@State var qLeft = 1
var body: some View {
NavigationView {
ZStack {
LinearGradient(gradient: Gradient(colors: [Color.yellow, Color.red]), startPoint: .topTrailing, endPoint: .bottomTrailing)
.edgesIgnoringSafeArea(.all)
VStack {
Text("Settings")
.frame(maxWidth: .infinity, alignment: .leading)
.padding(EdgeInsets(top: -20, leading: 20, bottom: 0, trailing: 0))
.font(.system(size: 30, weight: .semibold, design: .rounded))
Section(header: Text("Which table you wanna practice?")) {
Picker("Select Table", selection: $qLeft) {
ForEach(1 ..< 13) {
Text("\($0) Table")
}
}
.padding(EdgeInsets(top: -50, leading: 0, bottom: 0, trailing: 0))
}
.padding(EdgeInsets(top: 20, leading: 10, bottom: 0, trailing: 0))
.frame(maxWidth: .infinity, alignment: .leading)
Section(header: Text("How many questions do you want to answer ?")) {
Picker(selection: $userQ, label: Text("Select Questions")){
ForEach(noQ, id: \.self){
Text($0)
}
}
.padding(EdgeInsets(top: -60, leading: 0, bottom: 0, trailing: 0))
}
.padding(EdgeInsets(top: 20, leading: 10, bottom: 0, trailing: 0))
.frame(maxWidth: .infinity, alignment: .leading)
Section {
NavigationLink("Click to Begin",destination: Play())
.font(.system(size: 30, weight: .bold, design: .monospaced))
.foregroundColor(.white)
}
Spacer()
}
}.toolbar {
ToolbarItemGroup(placement: .navigation){
Text("Tables App")
.navMod()
}
}
}
}
}
struct Questions {
var text: String
var question = [Int] ()
var answer = [Int] ()
var actualAnswer: String
var questionLef = ContentView()
init() {
let questionRight = Int.random(in: 1...12)
let questionLeft = questionLef.qLeft
text = "\(questionLeft) * \(questionRight)"
actualAnswer = "\(questionLeft * questionRight)"
}
}
struct Play: View {
var question = Questions()
var Active1 = true
// @State private var leftQ = Questions().questionLeft
// @State private var rightQ = Questions().questionRight
var body: some View {
VStack {
// Text("\(leftQ)")
// .padding()
// Text("\(rightQ)")
// .padding()
Text("\(question.text)")
.padding()
Text("\(question.actualAnswer)")
.padding()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct Play_Previews: PreviewProvider {
static var previews: some View {
Play()
}
}