Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

SwiftUI Documentation

Posts under SwiftUI subtopic

Post

Replies

Boosts

Views

Activity

Slideshow / Gallery / Photos app View
How can I create a view that is like the one in the Photos app where you can select an item and it fills the window, then you can drag / swipe between items in that view? I have a working prototype, and it works for photos. But once I get to a video, the gesture no longer works.
1
0
19
15h
ViewThatFits and Text Truncation
I'm using ViewThatFits to handle different screen sizes as well as the orientation of the phone. Essentially, I have a smaller view that should only be used in portrait mode on the phone and a larger view that should be used in every other instance. The issue is that both of those views have a Text view that is bound to a String within a SwiftData model. If the String is too long the ViewThatFits considers that when choosing the appropriate subview. This results in a list of items where most items use one view while one or more may use the other view. It would be great if there was a modifier that could be applied to the Text view that resulted in the ViewThatFits ignoring it when determining the appropriate subview. Until such a modifier is available, has anyone come up with creative ways around this?
1
0
20
18h
encounter memory leak for SVG image
I have a memory leak for SVG image that located in Assets.xcassets file when using SwiftUI Image, but when I use UIImage then convert it to SwiftUI Image the issue is not found. import SwiftUI struct ContentView: View { var body: some View { NavigationStack { VStack { NavigationLink("Show", destination: SecondView()) } .padding() } } } struct SecondView: View { @Environment(\.dismiss) var dismiss var body: some View { NavigationStack { VStack { IM.svgImage .resizable() .scaledToFit() .frame(width: 200, height: 200) Button("Dismiss") { dismiss() } } } } } enum IM { static let testImage: Image = "test_image".image static let svgImage: Image = "svgImage".image } extension String { var image: Image { Image(self) // Memory leak } var imageFromUIImage: Image { guard let uiImage = UIImage(named: self) else { return Image(self) } return Image(uiImage: uiImage) // No Memory leak } } Environment that produces the issue: Xcode: 16.2 Simulator: iPhone 15 Pro (iOS 17.5)
1
0
20
1d
Can't display image in SwiftUI
I'm trying to display my apps icon within my app and it's not working. It displays a blank space instead and I don't understand why this is happening. I tried creating a new image (just a normal image, not an 'App Icon' image set) and have this code: Image("AppIcon") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 48) .cornerRadius(10) .overlay( RoundedRectangle(cornerRadius: 10) .stroke(Color.black.opacity(0.1), lineWidth: 1) ) For some strange reason it's not displaying that either. The image name is correct. It's showing a blank white box.
2
0
30
1d
SwiftUI lifecycle / CarPlay / data model
Is there a way to share a SwiftUI App's @Observable model into a CPTemplateApplicationSceneDelegate ? Is there an incantation to go from the UIApplicationDelegate via @UIApplicationDelegateAdaptor to the UISceneDelegate for CarPlay via a userInfo? I can't seem to figure it out. Otherwise I have to use a shared global, and I'd prefer not to have to do it this way. Any ideas? Thanks!
2
0
42
1d
iOS 26 Liquid Glass - How to achieve separate glass backgrounds for multiple leading toolbar items?
I'm updating my app for iOS 26's new Liquid Glass design and encountering unexpected behavior with toolbar items. I want to display multiple buttons on the leading side of the navigation bar, each with its own glass background (similar to how LandmarkDetailView shows separate glass backgrounds for its toolbar items). Current Behavior: When using .navigationBarLeading placement for multiple ToolbarItems, they all group under ONE glass background When using NO placement (like in Apple's LandmarkDetailView example), items get separate glass backgrounds but appear on the RIGHT side Using different leading placements (.topBarLeading vs .navigationBarLeading) still groups them together What I've Tried: swift// Attempt 1: All items with same placement - they group together .toolbar { ToolbarItem(placement: .navigationBarLeading) { Button(action: {}) { Image(systemName: "dollarsign.circle") } } ToolbarItem(placement: .navigationBarLeading) { Button(action: {}) { Image(systemName: "qrcode") } } } // Attempt 2: No placement - separate glass but wrong position .toolbar { ToolbarItem { Button(action: {}) { Image(systemName: "dollarsign.circle") } } ToolbarSpacer(.fixed) ToolbarItem { Button(action: {}) { Image(systemName: "qrcode") } } ToolbarSpacer(.flexible) } // Attempt 3: Different placements - still groups .toolbar { ToolbarItem(placement: .topBarLeading) { Button(action: {}) { Image(systemName: "dollarsign.circle") } } ToolbarItem(placement: .navigationBarLeading) { Button(action: {}) { Image(systemName: "qrcode") } } } Environment: Xcode 26 Beta iOS 26.0 Beta Using NavigationView (also tried NavigationStack) This is a root view (no back button) Questions: Is grouping of same-placement toolbar items the intended Liquid Glass behavior? How can I achieve separate glass backgrounds for multiple leading toolbar items? Why do items without placement appear on the right in a root view? Is there new API or guidance for toolbar layouts in iOS 26? I've studied the LandmarkDetailView example from Apple, but it uses no placement and relies on being a detail view with a back button. My use case is a root navigation view. Any guidance would be appreciated!
Topic: UI Frameworks SubTopic: SwiftUI
1
0
60
1d
Lack of API to access scrubber preview time in AVPlayerViewController (scrubbingTime)
Hi everyone, I'm working with AVPlayerViewController in a tvOS/iOS app and ran into a limitation that I believe some developers face. When using player.currentItem?.currentTime(), we only get the playback time—which is fine while the video is playing. But when the player is paused and the user drags the scrubber, there's no public API to get the time that is currently being previewed under the scrubber thumb (stick), but there's no way to read it programmatically. This becomes a problem when trying to show thumbnail previews or display metadata tied to the scrubbed position.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
1
28
2d
iOS26 beta ToolbarItem with placement to principal width is not fill to screen
I’m trying to add a TextField to the toolbar using .principal placement, and I want it to either fill the screen width or expand based on the surrounding content. However, it’s not resizing as expected — the TextField only resizes correctly when I provide a hardcoded width value. This behavior was working fine in previous versions of Xcode, but seems to be broken in Xcode 26. Not sure if this is an intentional change or a bug. i am using iOS26 beta and Xcode 26 beta struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() .toolbar { ToolbarItem(placement: .principal) { HStack { TextField("Search", text: .constant("")) .textFieldStyle(.roundedBorder) .frame(maxWidth: .infinity) // .frame(width: 300) Button("cancel") { } } .frame(maxWidth: .infinity) } } } } #Preview { NavigationView { ContentView() } }
0
0
42
2d
AlarmMetadata struct
How can AlarmMetadata be implemented? I have referenced the sample code from "Scheduling an alarm with AlarmKit" and used the following: import AlarmKit struct CookingData: AlarmMetadata { let createdAt: Date /* other properties */ init() { self.createdAt = Date() /* other properties here */ } } But it always has the following errors: Main actor-isolated conformance of 'CookingData' to 'Decodable' cannot satisfy conformance requirement for a 'Sendable' type parameter of 'Self' Type 'CookingData' does not conform to protocol 'AlarmMetadata'. However in the sample App, this error is not there. Any other guidance on AlarmMetadata protocol besides the documentation?
Topic: UI Frameworks SubTopic: SwiftUI
2
0
23
2d
Search in a bottom toolbar
Dear all, The Search fields documentation appears to make a distinction between putting a search in a tab bar and in a bottom toolbar in an iOS device. Putting a search in a tab bar in iOS26 appears to be quick and easy: Tab(role: .search) { // Search } I cannot find, however, a way on how to put a search bar in a bottom toolbar (as illustrated here). The following code puts it in the top toolbar: .searchable(text: $searchQuery, placement: .toolbar) Same as this one: .searchable(text: $searchQuery, placement: .toolbarPrincipal) Do I miss something in this regard? Thanks!
1
0
48
2d
@Observable with generic typed throw breaks SwiftCompile
@Observable seems not to work well with generic typed throw. The following code using @Observable with non-generic typed throw builds good: @Observable class ThrowsLoadingViewModel<R, E: Error> { private(set) var isLoading = true private(set) var error: E? = nil private(set) var data: R? = nil private var task: () throws(Error) -> R init(task: @escaping () throws(E) -> R) { self.task = task } func load() { do throws(Error) { self.data = try task() } catch { // self.error = error } self.isLoading = false } } But if I change Line 7 and 14 to generic, it'll breaks the build with a "Command SwiftCompile failed with a nonzero exit code" message : @Observable class ThrowsLoadingViewModel<R, E: Error> { private(set) var isLoading = true private(set) var error: E? = nil private(set) var data: R? = nil private var task: () throws(E) -> R init(task: @escaping () throws(E) -> R) { self.task = task } func load() { do throws(E) { self.data = try task() } catch { // self.error = error } self.isLoading = false } } A the same time, if I remove @Observable, the generic typed throw works again: class ThrowsLoadingViewModel<R, E: Error> { private(set) var isLoading = true private(set) var error: E? = nil private(set) var data: R? = nil private var task: () throws(E) -> R init(task: @escaping () throws(E) -> R) { self.task = task } func load() { do throws(E) { self.data = try task() } catch { // self.error = error } self.isLoading = false } } Currently the possible solution seems to fall back to use ObservableObject...
0
0
11
2d
Applying the `.prominent` modifier to a toolbar action
Hi y'all! I'm creating an iOS app with SwiftUI. Part of the app's layout will have a toolbar. Per the HIG's Toolbar article, under the section titled "Actions", the primary action in the toolbar should use the .prominent modifier. Unfortunately, I'm having issues finding information about this modifier in the SwiftUI reference documentation, and Xcode's code completion (the standard completions; I don't use the language model version) doesn't reveal anything that seems to be usable to create the desired effect. For reference, this is what the view currently looks like: VStack { } .toolbar { ToolbarItem(placement: .topBarTrailing) { Button("Add Something", systemImage: "plus") { print("perform action") } } } Is this modifier added to the button itself as .buttonStyle(.borderedProminent)? This seems to create an odd off-center layout shift in the Xcode preview, the Simulator, and my physical device. Is it added to the toolbar item with a similarly-named modifier? Thanks all! :)
1
1
55
2d
Issues with .zoom NavigationTransition to a sheet with a .medium detent
When using a .zoom navigation transition, where .matchedTransitionSource is applied to a button in a toolbar and the destination view is a sheet which is presented with PresentationDetent.medium, the transition works initially, but shortly after it completes, the sheet's background is dimmed and the text of the source button reappears abruptly. Code and a screenshot are below, though the effect is best observed when interacting with the view. // // ContentView.swift // ZoomNavigationTransitionSample // // Created by Matthew DuBois on 6/15/25. // import SwiftUI struct ContentView: View { @State private var isPresentingSheet = false @Namespace private var namespace var body: some View { NavigationStack { List { Text("Some content") } .navigationTitle("Sample") .toolbar { ToolbarItem(placement: .topBarTrailing) { Button("Button") { isPresentingSheet = true } .matchedTransitionSource(id: "button", in: namespace) } } .sheet(isPresented: $isPresentingSheet) { Text("Some sheet content") .navigationTransition(.zoom(sourceID: "button", in: namespace)) .presentationDetents([.medium]) } } } } #Preview { ContentView() }
1
0
27
3d
Unable to find Slider/UISlider neutralValue
An WWDC 25 a neutral value was demonstrated that allows the Slider to be 'coloured in' from the point of the neutral value to the current thumb position. Trying to use this in Dev release 1 I get errors saying no such modifier. Was this functionality released in Dev Release 1 or am I using it incorrectly?
3
0
37
3d