Post

Replies

Boosts

Views

Activity

Reply to Anyone have a pointer about a crash Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000010
just an observation, I would avoid the "!" in: selectedPenaltyLength = formatSeconds(gameState.penaltyLengths![0]) and use: init(gameState : GameState) { self.gameState = gameState selectedPenaltyLength = "" selectedPenaltyIndex = 0 separatePenaltyClock = false if let penalties = gameState.penaltyLengths, penalties.count 0 { selectedPenaltyLength = formatSeconds(penalties[0]) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to How to reverse the bounds parameter of a slider
You cannot "reverse" the bounds. You will have to use some very basic math to calculate the desired value. According to the docs, Slider takes a ClosedRange for the "in" parameter, and a ClosedRange is (https://docs.swift.org/swift-book/LanguageGuide/BasicOperators.html): "The closed range operator (a...b) defines a range that runs from a to b, and includes the values a and b. The value of a must not be greater than b."
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Not append new data in an array
what you are doing is resetting the "cart" to empty each time you call "Shop". Note, passing variables and etc... to another View is an important concept to master. Try this: struct ContentView: View { @ObservedObject var cart = Products() var body: some View { NavigationView { List { ForEach(cart.products) { product in Text("\(product.name) \(product.price)$") } } .navigationBarItems( trailing: NavigationLink(destination: Shop(cart: cart)) { // Text("Go Shop") }) .navigationBarTitle("Cart") }.navigationViewStyle(StackNavigationViewStyle()) } } struct Shop: View { @ObservedObject var cart:Products // var body: some View { VStack{ Button("Add Product To Cart") { cart.addProduct(product: Product(name: "Name", price: 399)) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to SwiftUI Alert in Previews is not shown
This is the full code I used on macos 11.4, xcode 12.5, target ios 14.5 and macCatalyst. Is this not working for you? import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { var body: some View { Alerts() } } struct Alerts: View { var body: some View { NavigationView { Text("Where is the Alert?") .alert(isPresented: .constant(true)) { Alert(title: Text("Hello"), message: Text("World")) } } } } struct Alerts_Previews: PreviewProvider { static var previews: some View { Alerts() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Unable to present. Please file a bug.
yes it works with List, however even without ScrollView the message still shows, but it works on iPhone. On Mac Catalyst, if I include StackNavigationViewStyle it shows the "error" but it works, whereas without it it doesn't work at all. I'm now on macos 11.4 beta2, target ios 14.5, testing on ios 14.6 iPhone. struct ContentView: View { var body: some View { NavigationView { VStack { NavigationLink(destination: Text("view 1")) { VStack{ Text("to view 1").padding(5) } } NavigationLink(destination: Text("view 2")) { VStack{ Text("to view 2").padding(5) } } NavigationLink(destination: Text("view 3")) { VStack{ Text("to view 3").padding(5) } } } }.navigationViewStyle(StackNavigationViewStyle()) // } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to TextEditor Problem, or me?
try this: struct ContentView: View { @State var text = "start text" init() { UITextView.appearance().backgroundColor = .clear } var body: some View { NavigationView { ZStack { Color.green.ignoresSafeArea() TextEditor(text: $text) } .navigationTitle("Notepad Test!") } } } or this, if you only want the text editor background color: struct ContentView: View { @State var text = "start text" var body: some View { NavigationView { TextEditor(text: $text).padding().colorMultiply(.green) .navigationTitle("Notepad Test!") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Unable to present. Please file a bug.
@bob_mosh, @shitingsand, your issues may not be related to the original NavigationLink problem. Show us some example code, maybe we can track down your particular issues. In my example I tried all sorts of things, @State, @StateObjects, @ObservedObject, var, etc.. without any impact.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Unable to present. Please file a bug.
Definitely something wrong with SwiftUI. Here is a simple example that shows "Unable to present. Please file a bug." on iOS, and does not work on Mac Catalyst. struct ContentView: View { @State var arr = ["1","2","3"] var body: some View { NavigationView { ScrollView { ForEach(arr, id: \.self) { name in NavigationLink(destination: Text("view \(name)")) { Text("to view \(name)").padding(5) } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21