Post

Replies

Boosts

Views

Activity

Reply to Section collapse triangle for section header no longer supported with NavigationStack?
You are correct in that you have to use the new initialisers with the isExpanded parameter to enable the expansion of sections. However, as of iOS 17 beta 1, this only works for lists with the sidebar style. Having spoken with an Apple engineer, it was agreed that this is not the intended behaviour and all list styles should have expandable sections. I did file a feedback report (FB12277169) so this should be resolved soon.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to Support for new ScrollView APIs on iOS 16 and earlier
No is the short answer. If the documentation says iOS 17+, it means iOS 17+. While you could be thinking that Apple could just use the @backDeployed attribute, it’s not that simple. It can only be applied to functions and computed properties and since the new scroll APIs require new types to work, it can’t be used. This is usually how each release of SwiftUI has been: new features are only compatible from that version onwards. You might hope that this could change with the official release later this year, but it’s unlikely.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to Reduce boilerplate while using @Query (SwiftData)
I believe it was mentioned in one of the WWDC activities that Query should support returning a single model object. As SwiftData is in its early stages anyway, the engineers are open to any feedback and enhancement requests. I suggest you file a feedback report detailing why you want Query to return a single model object as well as any useful use cases they can tailor to.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to Fullscreen Cover and Sheet Bug ? XCode 15 / iOS 17
While it could be a bug, I think there's another reason. You are attaching the sheet modifier to each button instance, so in your case there could be over 50 sheets ready waiting to be shown. Instead, you could create one sheet and show it when any of the buttons are pressed. Something like this works: struct TestButton: View { @Binding var isPresented: Bool var title: String = "No String" var body: some View { Button { isPresented.toggle() print("tapped") } label: { Text(title) } } } struct TestingBugView: View { @State private var isPresented = false var body: some View { NavigationStack { ScrollView { ScrollView(.horizontal) { LazyHStack { ForEach(1..<55, id: \.self) { num in TestButton(isPresented: $isPresented, title: num.description) } } .padding() .sheet(isPresented: $isPresented) { Text("presented") } } } } } } #Preview { TestingBugView() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to Is there a Plug In or SwiftUI Kit for changing measurements
The Foundation framework has built-in support for measurements and conversions. Here are some examples of how you can use the Measurement type and convert between different units: // Yards to Metres let yardsValue = Measurement(value: 50, unit: UnitLength.yards) let metresValue = yardsValue.converted(to: .meters) // Pints to Litres let pintsValue = Measurement(value: 10, unit: UnitVolume.pints) let litresValue = pintsValue.converted(to: .liters) // Pounds to Kilograms let poundsValue = Measurement(value: 100, unit: UnitMass.pounds) let kilogramsValue = poundsValue.converted(to: .kilograms)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to Missing parameter error in the first couple of steps
The session video you're referring to is from WWDC23, so it is using the new APIs introduced. The Map struct with the initialiser you are trying to use is only available from iOS 17 and aligned releases. To use these new features you will have to update to Xcode 15. In the meantime, use one of the old (marked as deprecated) initialisers that work in Xcode 14.3.1.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to How to perform an action based on the local time?
Your code doesn't work because of the way dates are created. Through your extension on Date, you are creating one from a string in the format of "HH:mm:ss" (hours, minutes, seconds). That is all the data the date has in order to be created so other values, such as day, month, year, are filled in from the reference date (00:00:00 UTC on 1 January 2001). In your case, the breakfast date is "01/01/2000 00:00:01". However, the now date has other date components (day, month, year…) provided and so won't be between two dates 23 years ago. With the code you have, you can just change the way you create the now variable like this: var now = Date.parse(Date().dateString()) This extracts the provided components in the format string from the current date using your extensions on Date.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to Navigation Link Syntax
Converting your example code to use the new APIs would look like this: NavigationStack { Button { isNavigating = true } label: { Text("Don't have an account? Sign Up") .foregroundColor(.blue) } .navigationDestination(isPresented: $isNavigating) { SignUpView() } } There is a lot more that can be done with NavigationLink and the navigationDestination modifier so I suggest you look at the documentation to see what else there is. You can also watch the What's new in SwiftUI and The SwiftUI cookbook for navigation session videos from WWDC22 as well as read the Migrating to new navigation types article for more details.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23