Post

Replies

Boosts

Views

Activity

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) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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 } }))
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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
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 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) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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 } }))
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to DragGesture translation reporting incorrect values
just an observation, you are not getting 3, it's 3e-05 = 0.00003 a very small number.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Nested NavigationLinks not working properly in latest SwiftUI
seeing the same problem.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’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:
Replies
Boosts
Views
Activity
Jul ’21
Reply to Delayed save when tapping "back" button using a SwiftUI DocumentGroup
cannot delete my post sorry.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’21
Reply to List with children on macOS 11.0 renders wrong data
Also works without any problems on macos 12.beta, xcode 13.beta, target ios 15 and macCatalyst 12. Tested on macOS 12 and iPhone ios 15.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’21
Reply to Do not allow camera crash app
show us the code you use to check for camera permission, for example where you use: "AVCaptureDevice.authorizationStatus(for: .video)"
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Jul ’21
Reply to I cannot manage to make var gracz1 and var gracz2 to update on a screen.
remove all "@State" in the "struct Player. "@State" is only for use in Views. You are also missing a closing bracket "} " in Player and Game. Also remove ":" and use "struct Player {"
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’21