Post

Replies

Boosts

Views

Activity

Reply to Error on Multipeer Connectivity after updating to Xcode 12 and iPadOS 14
I have just found a solution. Given this code example: assistant = MCAdvertiserAssistant(serviceType: "service", discoveryInfo: nil, session: session!) browser = MCBrowserViewController(serviceType: "service", session: session! ) It is sufficient to insert in the info.plist the following fields: 1) Privacy - Local Network Usage Description 2) Bonjour services with the following initialisation: \_service.\_tcp and \_service.\_udp
Sep ’20
Reply to How can I change a part of a view after a picker selection?
Thanks for your answer. No, my goal was not to insert if chain, but this seems to be the only way. I use @Binding and @State to access the subviews state. I thought there was something like this, as in other languages, so I could have had a cleaner code and take advantage of the polymorphism. var selectedView : any View /* or something like this */ var viewList : [View]
Jul ’20
Reply to How can I change a part of a view after a picker selection?
I would like to do something like this. struct FirstView: View{ @State var selectedValue = 0 var selectedView : some View = SubviewA() var body: some View{ VStack{ Picker(selection: $selectedValue, label: Text("someText")){ Text("A").tag(0)                    Text("B").tag(1)                    Text("C").tag(2)                    Text("D").tag(3)                    Text("E").tag(4)                    Text("F").tag(5)                }.pickerStyle(SegmentedPickerStyle()) selectedView } } } struct SubviewA: View{ var body: some View{ Text("Subview A") } } struct SubviewB: View{ var body: some View{ Text("Subview B") } } struct SubviewC: View{ var body: some View{ Text("Subview C") } } struct SubviewD: View{ var body: some View{ Text("Subview D") } } struct SubviewE: View{ var body: some View{ Text("Subview E") } } struct SubviewF: View{ var body: some View{ Text("Subview F") } } In the real scenario each subview is more complex than a simple Text. It has an image and a Picker, like this. struct SubviewRealExample: View {     @State var selection = [Int](repeatElement(0, count: 2))     var body: some View{         VStack{             ExercisePreview(background: "bgAcuity_thumb", symbol: ViewModel.getImageName())             MultiPicker(data: ViewModel.getData(), selection: $selection)         }     } } I would like selectedView to change every time the selected item in the picker changes. The only way that comes to my mind is the following. struct FirstView: View{ @State var selectedValue = 0 var body: some View{ VStack{ Picker(selection: $selectedValue, label: Text("someText")){ Text("A").tag(0)                    Text("B").tag(1)                    Text("C").tag(2)                    Text("D").tag(3)                    Text("E").tag(4)                    Text("F").tag(5)                }.pickerStyle(SegmentedPickerStyle()) if (selectedValue == 0){ SubviewA() }else if(selectedValue == 1){ SubviewB() }else if(selectedValue == 2){ SubviewC() }else if(selectedValue == 3){ SubviewD() }else if(selectedValue == 4){ SubviewE() }else if(selectedValue == 5){ SubviewE() }else{ EmptyView() } } } } struct SubviewA: View{ var body: some View{ Text("Subview A") } } struct SubviewB: View{ var body: some View{ Text("Subview B") } } struct SubviewC: View{ var body: some View{ Text("Subview C") } } struct SubviewD: View{ var body: some View{ Text("Subview D") } } struct SubviewE: View{ var body: some View{ Text("Subview E") } } struct SubviewF: View{ var body: some View{ Text("Subview F") } } If the subviews were only to be displayed I could use an Anyview array, but I need to access to the subviews state.
Jul ’20
Reply to How can I change a part of a view after a picker selection?
Here I add it. struct FirstView: View{ @State var selectedValue = 0 var body: some View{ VStack{ Picker(selection: $selectedValue, label: Text("someText")){                    Text("A").tag(0)                    Text("B").tag(1)                    Text("C").tag(2)                    Text("D").tag(3)                    Text("E").tag(4)                    Text("F").tag(5)                }.pickerStyle(SegmentedPickerStyle()) /* Here I want to choose different views depending on the item selected */ } } } struct SubviewA: View{ var body: some View{ Text("Subview A") } } struct SubviewB: View{ var body: some View{ Text("Subview B") } } /* One subview for each item in picker */ There must be one view for each item in picker. In the real scenario, each subview is more complex than a simple Text and has different image and different components. When the selected item changes, the corresponding subview must be displayed.
Jul ’20
Reply to How can I change a part of a view after a picker selection?
I want to choose different subview depending on the selected item in the picker. Here there is an example. struct FirstView: View{ @State var selectedValue = 0 var body: some View{ VStack{ Picker(selection: $selectedValue, label: Text("someText")){                     Text("A").tag(0)                     Text("B").tag(1)                     Text("C").tag(2)                     Text("D").tag(3)                     Text("E").tag(4)                     Text("F").tag(5)                 }.pickerStyle(SegmentedPickerStyle()) // Here I want to choose different views depending on the item selected } } }
Jul ’20