How do I read the tag #

No problem in displaying the Text, but how can I read the tag# with the print statement or the good old NSLog. format.

In the old way, I had no problem in capturing the tag # Thank you ahead of time for a reply.

struct SegmentedDirectorsCut: View {

var symbolsURL = ["Yes", "No"]

 @State private var directorCut = 1

  var body: some View {
     VStack {
       HStack {

           Picker(selection: $directorCut, label: Text("Picker")) {
                 ForEach(0 ..< symbolsURL.count) {
                        Text(self.symbolsURL[$0]).tag($0)
                 }
           }
           .pickerStyle(SegmentedPickerStyle())
           .padding(.all)
        }
    Text("Director Selected: \(symbolsURL[directorCut])")

     }
  }

}

#if DEBUG
struct SegmentedDirectorsCut_Previews: PreviewProvider {
static var previews: some View {
SegmentedDirectorsCut()
}
}
#endif

Hi @hcri1950,
What is it that you really want to do? If you want to get the tag, it is already in directorCut, however if you want to print it for debugging, then you can use a very simple trick.

   extension View {
    func debugPrint(_ msg: Any ...) -> Self {
        print(msg)
        return self
    }
  }

That’s all you need to do and now you can use it like

    Text("Director Selected: \(symbolsURL[directorCut])")
    .debugPrint("we selected : \(directorCut)")

cheers,

Jayant

1 Like

This is the second time that I did not get notified of a reply. THANK YOU for that has helped.

This topic was automatically closed after 166 days. New replies are no longer allowed.