Post

Replies

Boosts

Views

Activity

Reply to App Intents and the Document App Xcode Template
After I wrote the post above, I did extensive research. I read Apple’s documentation and quite a few web pages on the topic of App Intents and SwiftUI. This led me to refactor my app, pulling a couple of vars and a method out of the view, and putting them into model. On the advice of one site, I have chosen the document as the model. This leaves me with one, hopefully not intractable, problem. How do I reference the document from the App Entity and App Intent? This is not as easy as it might seem. The app is based on the SwiftUI Document Template. As such, the document is created inside the body of the App. The statements called out by the Apple documentation will not work in that environment. So, how do I connect up the document with the App Entity? Thanks, Don Carlile
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’26
Reply to Navigation, sheet, or overlay?
I figured out my own solution. Before I share that for the benefit of anyone else who is having this problem, I want to explain why a sheet will not work in this situation, at least not the way I have implemented it. The key to understanding is to note that the table is actually a loop, looping over the array of channels. When the showingViewSheet State variable is toggled, that kicks off a redraw of the view. The first item in the array is then displayed as a sheet, as it is the first item to be looped. The Dismiss button toggles that state variable again, but it does not stop the redraw, so the loop continues through the array, resulting in the flashing of the other items that I observed (see my comment). I don’t think I can pull that sheet code out of the inferred loop, so I decided to go with a ZStack instead.Here is the relevant code:     @State private var selectedChannel = blankChannels[0] var body: some View {         ZStack {             Table(channels, selection: $selection, sortOrder: $sortOrder) { . . .                 TableColumn("View/Edit") { channel in                      HStack {                          Button {                              selectedChannel = channel                              showingView.toggle()                          } label: {                             Label("", systemImage: "eye")                         } . . .                   }                  }             }             if(showingView)             {                 Color.white.opacity(1.0)                 VStack {                     ChannelDetailView(channel: selectedChannel)                     Spacer()                     Button("Dismiss") {                         showingView.toggle()                         selectedChannel = blankChannels[0]                     }                 }                 .padding()             }         }     } This worked, showing the info for the channel in which the eye was clicked: It's not completely optimal, but it will do for this application. Hope this helps someone else. Don Carlile
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’22
Reply to Navigation, sheet, or overlay?
I looked more carefully at the sheet dismissal. I found that the the reappearance of the sheet after dismissal showed the info for the second row. In fact, when I added another row, I got two reappearances, so the info for all the rows appears quickly. I have no idea why I am getting an iteration over teh entire table rather than the information for the one row which I clicked.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to App Intents and the Document App Xcode Template
After I wrote the post above, I did extensive research. I read Apple’s documentation and quite a few web pages on the topic of App Intents and SwiftUI. This led me to refactor my app, pulling a couple of vars and a method out of the view, and putting them into model. On the advice of one site, I have chosen the document as the model. This leaves me with one, hopefully not intractable, problem. How do I reference the document from the App Entity and App Intent? This is not as easy as it might seem. The app is based on the SwiftUI Document Template. As such, the document is created inside the body of the App. The statements called out by the Apple documentation will not work in that environment. So, how do I connect up the document with the App Entity? Thanks, Don Carlile
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’26
Reply to Navigation, sheet, or overlay?
I figured out my own solution. Before I share that for the benefit of anyone else who is having this problem, I want to explain why a sheet will not work in this situation, at least not the way I have implemented it. The key to understanding is to note that the table is actually a loop, looping over the array of channels. When the showingViewSheet State variable is toggled, that kicks off a redraw of the view. The first item in the array is then displayed as a sheet, as it is the first item to be looped. The Dismiss button toggles that state variable again, but it does not stop the redraw, so the loop continues through the array, resulting in the flashing of the other items that I observed (see my comment). I don’t think I can pull that sheet code out of the inferred loop, so I decided to go with a ZStack instead.Here is the relevant code:     @State private var selectedChannel = blankChannels[0] var body: some View {         ZStack {             Table(channels, selection: $selection, sortOrder: $sortOrder) { . . .                 TableColumn("View/Edit") { channel in                      HStack {                          Button {                              selectedChannel = channel                              showingView.toggle()                          } label: {                             Label("", systemImage: "eye")                         } . . .                   }                  }             }             if(showingView)             {                 Color.white.opacity(1.0)                 VStack {                     ChannelDetailView(channel: selectedChannel)                     Spacer()                     Button("Dismiss") {                         showingView.toggle()                         selectedChannel = blankChannels[0]                     }                 }                 .padding()             }         }     } This worked, showing the info for the channel in which the eye was clicked: It's not completely optimal, but it will do for this application. Hope this helps someone else. Don Carlile
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22
Reply to Navigation, sheet, or overlay?
I looked more carefully at the sheet dismissal. I found that the the reappearance of the sheet after dismissal showed the info for the second row. In fact, when I added another row, I got two reappearances, so the info for all the rows appears quickly. I have no idea why I am getting an iteration over teh entire table rather than the information for the one row which I clicked.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’22