Post

Replies

Boosts

Views

Activity

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") } } } }
Jul ’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.
Jun ’21
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
Jun ’21
Reply to SwiftUI Undo/Redo Buttons for TextEditor/Keyboard
I would try something like this: import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { var body: some View { TextEditorView() } } struct TextEditorView: View { @State private var fullText: String = "" @State private var undoText: [Character] = [] var body: some View { VStack { HStack { Button(action: undoType) {Image(systemName:"arrow.uturn.backward")} Button(action: redoType) {Image(systemName:"arrow.uturn.forward")} } TextEditor(text: $fullText) } } func undoType(){ if let lastChar = fullText.last { undoText.append(lastChar) fullText = String(fullText.dropLast()) } } func redoType(){ if let lastChar = undoText.last { undoText.removeLast() fullText.append(lastChar) } } }
Jun ’21
Reply to Break Line
Cannot reproduce the issue. Works for me on macos 12.beta, xcode 13.beta, target ios 14.7 and macCatalyst 12. Tested on macOS 12 and iPhone ios 14.7. import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State var test = "My text \nhas a break line" let test2 = "My text \nhas a break line" var body: some View { VStack (spacing: 30) { Text(test) Text(test.description) Text("\(test)") Text(test2) } } }
Jun ’21
Reply to In SwiftUI, any way to intercept each character entered in a TextField?
yes you can, try this: (newVal will give it to you) struct ContentView: View { @State var theText = "" var body: some View { TextField("type something", text: $theText) .onReceive(theText.publisher) { newVal in // do your checks here on newVal print("---> theText: \(theText) newVal: \(newVal) ") } } } you can also try this: TextField("type something", text: $theText) .onChange(of: theText) { newVal in if let lastChar = newVal.last { // do your check here on lastChar print("--> last char: \(lastChar)") } } here is another way: TextField("type something", text: Binding( get: { theText }, set: { newVal in if let lastChar = newVal.last { // do your checks here on lastChar print("--> last char: \(lastChar) newVal: \(newVal) theText: \(theText)") theText = newVal // if pass the checks } }))
Jun ’21
Reply to Repeating function in SwiftUI
you could try this: struct ContentView: View { var body: some View { Text("keep calling a function").padding() .onAppear { callFunc() } } func callFunc() { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { print("-----> callFunc") callFunc() } } }
Jun ’21
Reply to Using Text(_ : Date, style: DateStyle) in ScrollView causes crash
works well for me on macos 12.beta, xcode 13.beta, target ios 14.7 and macCatalyst 12. Tested on macOS 12 and iPhone ios 14.7. You could try "Text(Date() + 60, style: .relative)" struct ContentView: View { var body: some View { ScrollView { Text(.init() + 60, style: .relative) Text(.init() + 60, style: .date) Text(.init() + 60, style: .time) Text(.init() + 60, style: .timer) Text(.init() + 60, style: .offset) } } }
Jun ’21