Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Listview With Children Error
in your data structure you don't have a hierarchy of parent/children, you only have a flat array of MapLayerGroup each element containing an array of LayerGroup. So I guess the compiler cannot make sense of the non tree-structured data. Try a simple list in this case: List(mapLayerGroups, id: \.id) { layer in Text(layer.Name) } If your intention was to have a tree structure hierachy, then you should have something like this: struct MapLayerGroup: Hashable, Identifiable { var id = UUID() var children: [MapLayerGroup]? = nil // <--- var CanBeDeleted: Bool var ListOrder: Int var Mutual: Bool var Name: String var ProjectId: Int var ProjectLayerGroupId: Int var Xaml: String var LayerGroups: [LayerGroup]? } ... List(mapLayerGroups, children: \.children) { layer in Text(layer.Name) } See also the Apple doc (halfway down the page) at: Apple Documentation
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Http Request with Querystring Parameter
There is no "major" mistake in your code. However, with querying parameters in http, you have to use "?" to indicate this is a query string. If you have more than one parameter you need to separate them with "&". Something like: URL(string: "https://mysite.com/product?id=" + productId) You need to find out exactly how to query the server with productId.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Nested NavigationLinks not working properly in latest SwiftUI
there seem to be a lot of things not working properly with NavigationView/NavigationLink judging by the number of unresolved questions and strange workarounds. You can do this however, to let you select which list to go back to: struct InnerListView: View { var body: some View { NavigationView { // <--- here List(1..<100) { row in NavigationLink(destination: Text("Details for row \(row)")) { Text("Row \(row)") } .navigationTitle("Inner List") } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to Present SwiftUI without tap
there are many ways to do this, this is one way: import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State var goToIt = false var body: some View { NavigationView { NavigationLink(destination: Text("Second View"), isActive: $goToIt) { Text("Second view in 3 seconds") } }.onAppear { // simulating another process that triggers the change DispatchQueue.main.asyncAfter(deadline: .now() + 3) { goToIt = true } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to Char comparison not working
try this: func wordChained() -> Bool{ let char1 = prevWord[prevWord.index(prevWord.startIndex, offsetBy: prevWord.count - 1)] let char2 = playerWord[playerWord.index(playerWord.startIndex, offsetBy: 0)] if char1.lowercased() == char2.lowercased() { // <--- here return true } else{ return false } } or just: func wordChained() -> Bool{ let char1 = prevWord[prevWord.index(prevWord.startIndex, offsetBy: prevWord.count - 1)] let char2 = playerWord[playerWord.index(playerWord.startIndex, offsetBy: 0)] return char1.lowercased() == char2.lowercased() // <--- here }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to SwiftUI Toggle multiple times per frame
Here is a possible setup. I've used 2 states in a ObservableObject, one for the UI and one for the PSU. I change the UI only if there is a change. import SwiftUI @main struct TestApp: App { @StateObject var psu = PSUModel() var body: some Scene { WindowGroup { ContentView().environmentObject(psu) } } } class PSUModel: ObservableObject { @Published var uiState = false @Published var psuState = false } struct ContentView: View { @EnvironmentObject var psu: PSUModel var body: some View { VStack (spacing: 50) { Button("simulate a PSU change") { psu.psuState.toggle() } Toggle("", isOn: $psu.uiState) .toggleStyle(SwitchToggleStyle(tint: Color.green)) // changing the PSU state from the UI .onChange(of: psu.uiState) { value in // request(action: .PSU, param: psu) print("---> send to PSU: \(value)") psu.psuState = value } // receiving PSU state changes from the PSU .onReceive(psu.$psuState) { value in print("-----> received from PSU: \(value) ") // update the UI with what we received from the PSU, but only if there is a change if psu.uiState != value { psu.uiState = value } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21