Post

Replies

Boosts

Views

Activity

Reply to How to convert 'Binding<UIImage>' to expected argument type 'UIImage'
Doing this, like you did in the List example, works fine: ForEach($results) { $result in Image(uiImage: result.image) } Because you are passing a Binding of a collection to the data parameter of the ForEach, the content closure expects to be passed a Binding of one of the collection’s elements. This is why you can access this value with the $ prefix and then read the underlying value, in your case ImageData, without it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to update TabView background color
Because you are using a UIKit API in SwiftUI in an “unnatural“ way, I won’t work as expected. You’re right about it being sort of a one-time thing. Even Apple recommends staying away from this method: In general, you should not rely on implementation details of a framework (including SwiftUI) to achieve specific behaviors in your apps. In iOS 16, SwiftUI does gain a new modifier: toolbarBackground(_:for:). You can use it like this: ... .toolbarBackground(.red, for: .tabBar) I believe it only applies to the current view, so you can change the behavior at different levels of the hierarchy. See the documentation as there is a lot more you can customise now regarding bars.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Swift UI backward compatibility
Most, if not all, of the new iOS 16 features in SwiftUI will only be available from iOS 16 onwards. This is what Apple tends to do every release, so you will have to wait for your minimum deployment target to catch up with the version you need features from if you don’t want to have a lot of if-available checks. Saying this, there are some features from earlier versions of SwiftUI that, even though have been replaced, will still work on the latest versions. For example, in iOS 13-14 you would style a List like this: .listStyle(PlainListStyle()) Although in iOS 15 it was reworked to this: .listStyle(.plain) the older approach will still work. Furthermore, NavigationView has only been soft-deprecated so will continue to work as expected on iOS 16. Check the documentation to see the minimum platform deployment information for each API.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to How to convert NavigationLink tag and selection to value?
By rearranging the way properties are fed into SwiftUI, you can make it fit for the new APIs. Something like this should work: NavigationStack { List(workoutTypes) { workoutType in NavigationLink(workoutType.name, value: workoutType) } .navigationDestination(for: HKWorkoutActivityType.self) { workoutType in SessionPagingView() } } NavigationSplitView { List(workoutTypes, selection: $workoutManager.selectedWorkout) { workoutType in NavigationLink(workoutType.name, value: workoutType) } } detail: { SessionPagingView() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22