Binding issue

I want to change a binding value to just a normal one. How?

Answered by newwbee in 718524022

Short answer

  • If you are using Binding<SomeType>, then use wrappedValue
  • If you are using @Binding propertyWrapper then using just the variable name should give the value

Long Answer

import SwiftUI

struct Something {
    //This is using the Binding propertyWrapper
    @Binding var price1: Int
    
    func f1() {
        price1 //Int value
        $price1 //Binding to the Int
        let price2 = $price1 //Type of price2 is Binding<Int>
        price2.wrappedValue //Int value
    }
}

Accepted Answer

Short answer

  • If you are using Binding<SomeType>, then use wrappedValue
  • If you are using @Binding propertyWrapper then using just the variable name should give the value

Long Answer

import SwiftUI

struct Something {
    //This is using the Binding propertyWrapper
    @Binding var price1: Int
    
    func f1() {
        price1 //Int value
        $price1 //Binding to the Int
        let price2 = $price1 //Type of price2 is Binding<Int>
        price2.wrappedValue //Int value
    }
}

Binding issue
 
 
Q