title: How to reference a value of a constant from a different view Swift
body: <p>I would like to reference a value of a constant from a different view. I looked online how to do so but most of the search results are outdated or don't work.</p>
  <p>I would like to reference the value of <code>oneRepMax</code> in a <code>struct ProgressiveOverload</code>.</p>
  <p>I want to import <code>oneRepMax</code> from here:</p>
  <pre><code>import SwiftUI
  
  struct OneRepMaxCalculator: View {
      
      @State private var reps = 1.0
      @State private var weight = 0.0
      
      var body: some View {
          NavigationView{
              Form{
                  Section(header: Text(&quot;Weight&quot;)) {
                      TextField(&quot;Weight: \(weight.formatted())kg&quot;, value: $weight, format: .number)
                  }
                  Section(header: Text(&quot;Reps&quot;)) {
                      Stepper(&quot;Reps : \(reps.formatted())&quot;, value: $reps, in: 1...10)
                  }
                  
              //THIS CONSTANT
              let oneRepMax = reps == 1.0 ? weight : weight*(1+(0.0333*reps))-2
                  
                  
                  if oneRepMax &gt; 0 {
                      Text(&quot;Your 1RM is: \(oneRepMax.formatted())kg&quot;)
                          .font(.headline)
                  }
  
                  if weight &gt; 0 {
                  Section(header: Text(&quot;2RM-10RM&quot;)) {
                      Menu(&quot;View All From 2RM-10RM&quot;) {
                          Text(String(format: &quot;Your 2RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*2))+2, oneRepMax/(1+(0.0333*2))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 3RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*3))+2, oneRepMax/(1+(0.0333*3))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 4RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*4))+2, oneRepMax/(1+(0.0333*4))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 5RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*5))+2, oneRepMax/(1+(0.0333*5))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 6RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*6))+2, oneRepMax/(1+(0.0333*6))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 7RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*7))+2, oneRepMax/(1+(0.0333*7))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 8RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*8))+2, oneRepMax/(1+(0.0333*8))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 9RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*9))+2, oneRepMax/(1+(0.0333*9))+2))
                                  .font(.footnote)
                          Text(String(format: &quot;Your 10RM is %.1fkg&quot;, oneRepMax/(1+(0.0333*10))+2, oneRepMax/(1+(0.0333*10))+2))
                                  .font(.footnote)
                          }
                      }
                  }
                  
                  if oneRepMax &gt; 0 {
                      Section(header: Text(&quot;Progressive Overload&quot;)){
                      NavigationLink(destination: ProgressiveOverload()) {
                          Text(&quot;Apply Progressive Overload&quot;)
                          }
                      }
                  }
                  
                  if weight == 0 &amp;&amp; reps &gt; 1 {
                  Section(header: Text(&quot;Warning&quot;)){
                      Text(&quot;Add Weight First&quot;)
                          .font(.callout)
                      }.foregroundColor(Color.red)
                          
                  }
                  
              }.navigationBarTitle(Text(&quot;One Rep Max Calculator&quot;))
          }
      }
  }
  
  struct OneRepMaxCalculator_Previews: PreviewProvider {
      static var previews: some View {
          OneRepMaxCalculator()
              .preferredColorScheme(.dark)
      }
  }
  </code></pre>
  <p>To here:</p>
  <pre><code>import SwiftUI
      
  struct ProgressiveOverload: View {
      
      var body: some View {
          NavigationView{
              Form{
                  Text(&quot;Your 1RM is \(oneRepMax)&quot;)
              }
          }
      }
  }
  
  struct ProgressiveOverload_Previews: PreviewProvider {
      static var previews: some View {
          ProgressiveOverload()
      }
  }
  </code></pre>