1
struct FirstView: View{
@State var MyDate = Date()
    var body: some View{
        Text("Hello world")
    }
}

struct  FirstView_Previews: PreviewProvider {
    static var previews: some View {
        FirstView()
    }
}



struct SecondView: View{
@Binding var MyDate: Date
@State var Thatdate = Date()
    var body: some View{
        Text("Hello world")
    }
}

struct  SecondView_Previews: PreviewProvider {
    static var previews: some View {
        SecondView(MyDate: <#Binding<Date>#>) <----- My problem is here
    }
}



struct ThirdView: View{
@Binding var MyDate: Date
@Binding var ThatDate: Date
    var body: some View{
      if Mydate == ThatDate{
      // do this 
        Text("Hello world")
    }
}

My question is how can i pass the binding date between views for comparing dates ? what is the binding date that should be instead of the shown above which is <#Binding#>, thank you for your help

  • 3
    You can pass a constant binding, `.constant(Date())`, to be used for the preview – Joakim Danielson Mar 06 '22 at 16:40
  • 1
    Does this answer your question? [SwiftUI @Binding Initialize](https://stackoverflow.com/questions/56685964/swiftui-binding-initialize) – burnsi Mar 06 '22 at 16:46
  • Thank you burnsi, Joakim answer is the right one , thank you joakim ☺️ –  Mar 06 '22 at 16:50

0 Answers0