4 Replies
Latest reply on Jan 17, 2020 12:55 PM by Claude31
Level 1 (0 points)

//First View

struct FinanceInput: View {

@State private var price: Double = 0.0

@State private var down: Double = 0.0

@State private var apr: Double = 0.0

//I know I am not representing 'rate' correctly here--just stuck

NavigationLink(destination: (FinanceOutput(price: self.\$price, down: self.\$down, apr: self.\$apr, rate: Double))) {...

get Error: 'Double.Type' is not convertible to 'Double

//Second View

struct FinanceOutput: View {

@Binding var price: Double

@Binding var down: Double

@Binding var apr: Double

private var rate: Double {

return apr/12

}

//    private var TotalFrequency : Float {

//           return mhzValue + mhzValueStep

init(price: Binding<Double>, down: Binding<Double>, apr: Binding<Double>, of rate: Double) {

self._price = price

self._down = down

self._apr = apr

}

• ###### Re: How to represent a View with @Binding and private variables in Navigationlink(_:destination)?
Level 8 (7,845 points)

Why don't you declare rate as the other var ?

```struct FinanceOutput: View {
@Binding var price: Double
@Binding var down: Double
@Binding var apr: Double
@Binding var rate: Double {```

```struct FinanceInput: View {
@State private var price: Double = 0.0
@State private var down: Double = 0.0
@State private var apr: Double = 0.0
@State private var rate: Double = 0.0```

`  NavigationLink(destination: (FinanceOutput(price: self.\$price, down: self.\$down, apr: self.\$apr, rate: self.\$rate)) {...`
• ###### Re: How to represent a View with @Binding and private variables in Navigationlink(_:destination)?
Level 8 (7,845 points)

In fact, you do this if you want to be able to change the value in FinanceOutput from FinanceInput.

Note that names may be different

```struct FinanceOutput: View {
@Binding var price: Double
@Binding var down: Double
@Binding var apr: Double
@Binding var rateOut: Double {```

```struct FinanceInput: View {
@State private var price: Double = 0.0
@State private var down: Double = 0.0
@State private var apr: Double = 0.0
@State private var rateIn: Double = 0.0

NavigationLink(destination: (FinanceOutput(price: self.\$price, down: self.\$down, apr: self.\$apr, rateOut: self.\$rateIn)) {...```

But if you don't want to be able to change rateOut you can simply declare

```struct FinanceOutput: View {
@Binding var price: Double
@Binding var down: Double
@Binding var apr: Double
var rateOut: Double {```

```struct FinanceInput: View {
@State private var price: Double = 0.0
@State private var down: Double = 0.0
@State private var apr: Double = 0.0
var rateIn: Double = 0.0

NavigationLink(destination: (FinanceOutput(price: self.\$price, down: self.\$down, apr: self.\$apr, rateOut: rateIn)```
• ###### Re: How to represent a View with @Binding and private variables in Navigationlink(_:destination)?
Level 1 (0 points)

You gave me a good idea from your responses.  This is my FinanceInput View:

@State private var price: Double = 0.0

@State private var down: Double = 0.0

@State private var apr: Double = 0.0

@State private var rate: Double = 0.0

var body: some View {

ScrollView {

NavigationLink(destination: (FinanceOutput(price: self.\$price, down: self.\$down, apr: self.\$apr, rate: self.\$rate))) {

Text("Numbers Check")

}.navigationBarTitle("Monthly Payment")

The above is what you suggested //Thank you!!!

But I did try something a bit different because I needed computed variables for my FinanceOutput View:

struct FinanceOutput: View {

@Binding var price: Double

@Binding var down: Double

@Binding var apr: Double

private var rate: Double { //This is where I deviated

return apr/12

}

//    private var TotalFrequency : Float {

//           return mhzValue + mhzValueStep

init(price: Binding<Double>, down: Binding<Double>, apr: Binding<Double>, rate: Binding<Double>) {

self._price = price

self._down = down

self._apr = apr

//check out the init and the numbers are correct

}

• ###### Re: How to represent a View with @Binding and private variables in Navigationlink(_:destination)?
Level 8 (7,845 points)

Great it works.

Happy to see my answer helped. What did you have to change in it ?

have a good day.