Post

Replies

Boosts

Views

Activity

Reply to passing nil to `perferredColorScheme` instead of light/dark
This has been resolved iOS 14.5 beta 2. You can view the release notes - https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-14_5-beta-release-notes for more information on new features and resolved issues. Setting .preferredColorScheme(nil) now correctly resets to the system’s preferred color scheme. (67000774) If you are not using the latest beta software or Xcode releases then you will have to wait for the final release of iOS 14.5 which should be available in a couple of weeks.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to @State not working on Swift Playgrounds
I have run your code and experienced the same problem. You can fix this by clicking on the speedometer button in the bottom left of the canvas and turning off Enable Results. The labels to the right of the lines of code will disappear but that is at the cost of improving performance. This is either a bug with Playgrounds or an intentional feature. My advice is that when using SwiftUI, turn off this setting so that Playgrounds doesn’t have to work any harder to give you the extra results and instead focuses on rendering your views in the canvas.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Change ListStyle based on horizontalSizeClass
I think I have found a temporary solution to this, albeit not the best one. Swift struct AdaptiveListStyle: ViewModifier { @Environment(\.horizontalSizeClass) private var horizontalSizeClass @ViewBuilder func makeBody(content: Content) { if horizontalSizeClass == .compact { content.listStyle(GroupedListStyle()) } else { content.listStyle(InsetGroupedListStyle()) } } } This will only work for just GroupedListStyle and InsetGroupedListStyle (static). I couldn’t find a way to pass in ListStyles without Xcode throwing many errors about mismatching types and generics, so I left that alone. If anyone can fix this or provide a workaround to the original problem, it would be much appreciated.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to SwiftUI tutorial
You can use .filter(_:) to filter through an array providing a closure that should return true or false depending on whether the element should appear in the filtered array. For the landmarks example, you can think of it as filter through the landmarks array and if we are not showing favourites only or the current element is favourited then this element should be filtered out into the new array. That might sound a bit confusing so you can also take a look at the documentation - https://developer.apple.com/documentation/swift/sequence/3018365-filter for a better summary.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to In a SwiftUI three split navigation view on iPad, how to check if the primary is folded?
You can use the onAppear and onDisappear modifiers on the primary view in the NavigationView. For example: Swift NavigationView { Text("Primary") .onAppear { print("Unfolded") } .onDisappear { print("Folded") }         Text("Supplementary") Text("Secondary") } The primary view is folded by default, so you can toggle an @State boolean variable when the primary view appears (unfolds) and disappears (folds).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to In a SwiftUI three split navigation view on iPad, how to check if the primary is folded?
I think that might be the only quirk with that particular solution. I’m sure there’s a workaround to this, or just an entirely different solution, but I’m confident you can solve this - maybe another boolean that is true on app launch and then toggled to false afterwards. Hopefully, Apple can introduce better APIs for these features at WWDC21.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Error when previewing on device
I don’t know if I’m sad or just frustrated but Xcode 12.5 has not resolved this either, at least not for me anyway, throwing the same error as last time. The feedback that I submitted previously has less than ten recent similar reports, but Apple hasn’t responded to it. I guess at this point, we’d be waiting for on-device previews to work in Xcode 13.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to SwiftUI: forcing focus based on state with TabView and watchOS
I also ran into this problem. I had a custom stepper control in one tab and a Slider in the other tab. I made the custom stepper control respond to the digital crown and made it focusable(). When running the app, going to the second tab worked but returning back to the first froze the whole app. I couldn't get this working properly again. I tried using the new @FocusState property wrapper to control which tab had focus, but that didn't work. I was using Xcode 13, so I didn't know if this was a beta bug.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Button to another View
There are two main ways of showing a new view. Using a NavigationLink to push to a new view: NavigationView { NavigationLink(destination: NewView()) { Text("Show new view") } } // make sure to embed in a NavigationView Showing a sheet or full screen cover (slides up from the bottom) with the new view: @State private var showingNewView = false Button { showingNewView = true } label: { Text("Show new view") } .sheet(isPresented: $showingNewView) { NewView() } Documentation links: NavigationLink Sheet Full screen cover
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21