Post

Replies

Boosts

Views

Activity

Reply to @State not updating when set via .init([...]) parameter
But if you change __internalNumber from @State to @Binding it will bind to any changes as a result of any external @State side effects. public struct TestView: View {     var number: Int     @Binding private var _internalNumber: Int     public init(number: Int) {         self.number = number         self.__internalNumber = Binding.constant(number) // bind __internalNumber to changes of the external @State variable     }   public var body: some View {     VStack(alignment: .leading) {       Text("number: \(number)")       Text("internal: \(_internalNumber)")     }     .debugAction {       Self._printChanges()       print("number: \(number)")       print("_internalNumber: \(_internalNumber)")     }   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to Menu Picker .onChange (doesn't work for the first selection)
This example shows that it does print on the first selection: import SwiftUI struct ContentView: View {     @State var fruitName: String = "none"     var body: some View {         VStack {             Menu {                 PickFruit(fruitName: $fruitName)             } label: {Text("Select A Fruit")}             Text(fruitName)         }         .onChange(of: fruitName) { [fruitName] newValue in // move onchange to here             print(newValue)             print(fruitName)         }     } } struct PickFruit: View {     let myFruits: [String] = ["Apple","Banana","Grape","Peach"]     @Binding var fruitName: String     var body: some View {         VStack {             Text(fruitName)             Picker("Select", selection: $fruitName) {                 ForEach(myFruits, id: \.self) { myFruits in                     Text(myFruits)                 }             }         }     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to SecKeyCreateRandomKey for SecureEnclave crash on iOS 13 simulator
If running on the simulator the MacBook must be equipped with a touch bar or touch id otherwise should be supported on an A7 or later A-series CPU. To prevent the crash on a sim with a touch bar or touch id remove kSecAttrTokenID as String: kSecAttrTokenIDSecureEnclave, or exclude it from sim builds. https://developer.apple.com/documentation/security/certificate_key_and_trust_services/keys/storing_keys_in_the_secure_enclave
Topic: Privacy & Security SubTopic: General Tags:
May ’22