Search results for

“swiftui”

17,354 results found

Post

Replies

Boosts

Views

Activity

Reply to Having trouble making swipe actions work on list items when the list is inside a horizontal ScrollView
Hello @yuval-nachman, Thank you for your post. It sounds like the .swipeActions aren’t being registered because that gesture is used to scroll horizontally for pagination. If this is not the case, please provide more information and include a code snippet that reproduces the issue. Because ScrollView’s pagination recognizer sits higher in the view hierarchy, the ScrollView claims the touch first. SwiftUI has no API for controlling gesture recognizer priority, like UIKit does with require(toFail:), which is for this exact scenario. As a workaround, consider changing the input method for list row from a .swipeAction to a .contextMenu or button, or try using next/previous page buttons instead of swiping to change pages, since thats the same recognizer that .swipeActions works with. When it comes to designing UX, there is likely something in the Design HIG that applies to your use case: See Designing for iOS. Lastly, hearing your use case would be useful in an Enhancement Request. If you file an enhancem
Topic: UI Frameworks SubTopic: SwiftUI
1w
Reply to SwiftUI on macOS equivalent of NSSavePanel for choosing a destination URL?
Thanks for the clear write-up. Your reading is correct. As of macOS 26, SwiftUI's file modifiers are fileImporter (open, returns URLs), fileExporter (writes a document or Transferable item you supply), and fileMover (moves an existing file). None of them return a bare destination URL the way NSSavePanel does, so there is no SwiftUI equivalent for choosing a save location and getting a URL back. Presenting .fileExporter with an empty placeholder document only to read its URL writes an empty file and works against how the modifier operates, so it is not a substitute. NSSavePanel is the supported way to get that destination URL, and using it from a SwiftUI app is a normal use of AppKit, not a workaround. You present it from your SwiftUI action, read panel.url, and pass that URL to your database. Since you create the file at that location, the sandbox behavior is relevant: the NSSavePanel documentation notes that when someone saves through the panel, macOS adds the chosen file
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1w
SwiftUI on macOS equivalent of NSSavePanel for choosing a destination URL?
In AppKit, NSSavePanel can be used to ask the user for a destination URL before the app creates a file. What is the SwiftUI equivalent for this? .fileImporter covers the NSOpenPanel case well enough, but I have not found a SwiftUI API that matches the simple NSSavePanel case where the app only needs the URL. There's a new API in .fileExporter that appears close, but it requires a non nil WritableDocument, and seems designed around SwiftUI performing the file export. My use case is a macOS app that creates new documents backed by SQLite. SQLite needs a file path so it can create the database at that location. With NSSavePanel, I can ask the user where to save the document, receive a URL, and then create the SQLite database myself. Is there a SwiftUI API for this on macOS 26 or later? If not, is NSSavePanel still the recommended approach for this case?
6
0
151
1w
LongRunningIntent run from in the app?
If I attempt to use a LongRunningIntent from a SwiftUI Button, using the Button(_:AppIntent:) control, I get the following errors: [LongRunningIntent <>>] No IntentContext available performBackgroundTask threw: noContext Intent failed to execute with error: LNPerformActionErrorCodeUnsupportedValueType It runs as expected when run from the Shortcuts app, but fails when run from a button within the app. Feedback ID (with sample app): FB23492034
1
0
110
1w
TimeDataSource .dateRange(endingAt:) won't update
Hello, I'm trying to add a new Live Activity to my app showing a timer to a specific date and time. I thought I could use some TimeDataSource so that the timer would be updated automatically by SwiftUI without relying on Live Activity updates. That's not the case with .dateRange(endingAt:) though. Text(.dateRange(endingAt: targetDate), format: .components(style: .narrow)) Something like this correctly shows the timer exactly how I want it, but it never updates. Other TimeDataSource like .currentDate and .durationOffset(to:) do update automatically, but are not what I'm looking for. Am I missing something? Should I use another formatter to make it work?
0
0
175
1w
Presenting content on Connected Display not working on iOS 27
I have an app that displays different content on a connected display (following this guide). It's working fine on iOS 26 but no longer is working in iOS 27 (both dev betas) + the latest SDKs. I tried to find any update notes but I couldn't find anything so I'm not sure if I'm doing something wrong or if it's an actual bug. I was able to simplify it down to the simplest case here: import SwiftUI // App Delegate to setup the scene delegate @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { print(Calling didFinishLaunchingWithOptions) return true } func application(_: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options _: UIScene.ConnectionOptions) -> UISceneConfiguration { print(Calling configurationForConnecting) let sceneConfig = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) sceneConfig.delegateCl
2
0
158
1w
Reply to Labels in toolbar menu get wrapped when upgrading from iOS 18 to 26
Hello @1066, Thank you for your post. In iOS 26, this is controlled by the system, however, in the 27 releases, SwiftUI introduces new toolbar APIs to control how these items are displayed as your app resizes. Use visibilityPriority modifier to keep important groups of toolbar items visible. Use toolbarOverflowMenu to permanently place lower priority toolbar items into the overflow menu. User topBarPinnedTrailing to pin needed toolbar items to the trailing edge at all times. Check out the WWDC26 What’s new in SwiftUI session for more new updates which might relevant to your project.  Travis
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1w
Labels in toolbar menu get wrapped when upgrading from iOS 18 to 26
When upgrading an app from iOS 18 to iOS 26, some labels in a toolbar menu get wrapped unexpectedly. The issue can be reproduced through the sample below, which contains this label : Envoyer une réaction On iPhone with iOS 18, the label is displayed on 1 line. But on iPhone with iOS 26, the label is displayed on 2 lines. No improvement was obtained through these modifiers : .lineLimit, .frame and .fixedSize . . How to avoid this unnecessary label wrapping that disrupts the readability ? . . import SwiftUI struct SampleView: View { var body: some View { NavigationStack { Color.clear .toolbar { ToolbarItem { Menu { Button(action: {}) { Label(Envoyer une réaction, systemImage: envelope) } } label: { Image(systemName: ellipsis) } } } } } } #Preview { SampleView() }
2
0
137
1w
Reply to SwiftUI 6 AttributeGraph warnings in console
Thanks for the very interesting post. I’m a little confused and I’m guessing too much for a Monday I think. The reason you are seeing this AttributeGraph: cycle detected warning comes down to how Swift Concurrency, I think. However because your code is a minimal reproducible example, the correct fix depends on what you are actually doing between isWorking = true and isWorking = false in your real app. I don’t see how that code will produce anything. In SwiftUI, Button actions are implicitly isolated to the @MainActor. When you create a Task { ... } inside a button action, that Task should inherits the MainActor. Because your Task is already on the MainActor, calling await MainActor.run { ... } does not actually suspend or switch threads. It should executes synchronously. You are setting isWorking = true and then instantly setting isWorking = false in the exact same runloop without any code or anything to run between them? If your real app does some heavy calculations or data parsing between the two s
Topic: UI Frameworks SubTopic: SwiftUI
1w
SwiftUI 6 AttributeGraph warnings in console
On a MacBook Air M4 running macOS Sequoia 15.7.7, the following tiny code does warn inside the Xcode 26.3. Here is the whole console output: === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 110216 === === AttributeGraph: cycle detected through attribute 110216 === === AttributeGraph: cycle detected through attribute 110284 === === AttributeGraph: cycle detected through attribute 110284 === === AttributeGraph: cycle detected through attribute 110216 === === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 110216 === Here is the full code: import SwiftUI @main struct myApp: App { var body: some Scene { WindowGroup { BaseView() } } } struct BaseView: View { @State private var isWorking: Bool = false var body: some View { Button(Go) { Task { // Attr
Topic: UI Frameworks SubTopic: SwiftUI
4
0
159
1w
iOS 27 ImagePlaygroundViewController.Delegate not working?
In the WWDC 2026 sessions it was called out in code that the helper functions would still work, however they don't seem to be working either inside a UIViewRepresentable, nor as a UIKit View as below (also tried as a sheet, to no avail). Otherwise it works. Is there something else I'm missing? import SwiftUI import ImagePlayground @available(iOS 27.0, *) final class ImagePlaygroundPopupController: UIViewController { var sourceImage: UIImage var prompt: String var onComplete: (URL) -> Void var onCancel: () -> Void private var didPresent = false private var playgroundVC: ImagePlaygroundViewController? init( sourceImage: UIImage, prompt: String, onComplete: @escaping (URL) -> Void, onCancel: @escaping () -> Void ) { self.sourceImage = sourceImage self.prompt = prompt self.onComplete = onComplete self.onCancel = onCancel super.init(nibName: nil, bundle: nil) view.backgroundColor = .clear } required init?(coder: NSCoder) { fatalError(init(coder:) has not been implemented) } override func viewD
0
0
137
1w
WorldAnchor instantly removed when SpatialTrackingSession and ARKitSession run together
Bug: When SpatialTrackingSession and ARKitSession + WorldTrackingProvider are running concurrently, any WorldAnchor added via WorldTrackingProvider.addAnchor() triggers .added followed immediately by .removed—without any user call to removeAnchor(). The anchor never persists in allAnchors. import SwiftUI import RealityKit import ARKit struct ImmersiveView: View { @State private var worldTracking: WorldTrackingProvider? @State private var arSession: ARKitSession? @State private var processWorldTrackingUpdatesTask: Task? var body: some View { RealityView { content in let configuration = SpatialTrackingSession.Configuration(tracking: [.world]) if let unavailableCapabilities = await SpatialTrackingSession().run(configuration) { if unavailableCapabilities.anchor.contains(.world) { fatalError(World tracking is not available on this device.) } } let worldTracking = WorldTrackingProvider() let arSession = ARKitSession() self.arSession = arSession try! await arSession.run([worldTracking]) self.worldTracking =
4
0
305
2w
Reply to How to get Ask Siri context menu button
Hello @Jordan, From WWDC26 session: Modernize your UIKit app Menus will automatically display this item when there's content relevant for Siri. To provide more relevant information specific to your app, use the new View Annotations API. With it you can annotate specific views with AppEntities. For SwiftUI: Use .appEntityIdentifier() on something like each cell inside of a ForEach: ForEach(items) { item in CellView(item: item) .appEntityIdentifier( EntityIdentifier(for: MyItemEntity.self, identifier: item.id) ) .contextMenu { ... } } This is the View Entity Annotation API from session 343: Explore advanced App Intents features for Siri and Apple Intelligence Note: MyItemEntity must conform to AppEntity with a persistent identifier. For more information see: App Intents I hope this helps!  Travis
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2w
Reply to Interface Builder is barely usable
IB is such a perfect tool to visually build a layout, I am very sad to see it so neglected. Fully agree. Doing in code makes is so hard to understand and quasi impossible to maintain. And I don't find SwiftUI so good to design precise UI (where many items need to be precisely positioned). I compared Xcode 26.3 and 16.4 : 26.3 takes between 9 and 12s to open the first view in IB, instead of 6s. Would be really interesting to know what it does differently.
2w
Reply to Having trouble making swipe actions work on list items when the list is inside a horizontal ScrollView
Hello @yuval-nachman, Thank you for your post. It sounds like the .swipeActions aren’t being registered because that gesture is used to scroll horizontally for pagination. If this is not the case, please provide more information and include a code snippet that reproduces the issue. Because ScrollView’s pagination recognizer sits higher in the view hierarchy, the ScrollView claims the touch first. SwiftUI has no API for controlling gesture recognizer priority, like UIKit does with require(toFail:), which is for this exact scenario. As a workaround, consider changing the input method for list row from a .swipeAction to a .contextMenu or button, or try using next/previous page buttons instead of swiping to change pages, since thats the same recognizer that .swipeActions works with. When it comes to designing UX, there is likely something in the Design HIG that applies to your use case: See Designing for iOS. Lastly, hearing your use case would be useful in an Enhancement Request. If you file an enhancem
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
1w
Reply to SwiftUI on macOS equivalent of NSSavePanel for choosing a destination URL?
Thanks for the clear write-up. Your reading is correct. As of macOS 26, SwiftUI's file modifiers are fileImporter (open, returns URLs), fileExporter (writes a document or Transferable item you supply), and fileMover (moves an existing file). None of them return a bare destination URL the way NSSavePanel does, so there is no SwiftUI equivalent for choosing a save location and getting a URL back. Presenting .fileExporter with an empty placeholder document only to read its URL writes an empty file and works against how the modifier operates, so it is not a substitute. NSSavePanel is the supported way to get that destination URL, and using it from a SwiftUI app is a normal use of AppKit, not a workaround. You present it from your SwiftUI action, read panel.url, and pass that URL to your database. Since you create the file at that location, the sandbox behavior is relevant: the NSSavePanel documentation notes that when someone saves through the panel, macOS adds the chosen file
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
1w
SwiftUI on macOS equivalent of NSSavePanel for choosing a destination URL?
In AppKit, NSSavePanel can be used to ask the user for a destination URL before the app creates a file. What is the SwiftUI equivalent for this? .fileImporter covers the NSOpenPanel case well enough, but I have not found a SwiftUI API that matches the simple NSSavePanel case where the app only needs the URL. There's a new API in .fileExporter that appears close, but it requires a non nil WritableDocument, and seems designed around SwiftUI performing the file export. My use case is a macOS app that creates new documents backed by SQLite. SQLite needs a file path so it can create the database at that location. With NSSavePanel, I can ask the user where to save the document, receive a URL, and then create the SQLite database myself. Is there a SwiftUI API for this on macOS 26 or later? If not, is NSSavePanel still the recommended approach for this case?
Replies
6
Boosts
0
Views
151
Activity
1w
LongRunningIntent run from in the app?
If I attempt to use a LongRunningIntent from a SwiftUI Button, using the Button(_:AppIntent:) control, I get the following errors: [LongRunningIntent <>>] No IntentContext available performBackgroundTask threw: noContext Intent failed to execute with error: LNPerformActionErrorCodeUnsupportedValueType It runs as expected when run from the Shortcuts app, but fails when run from a button within the app. Feedback ID (with sample app): FB23492034
Replies
1
Boosts
0
Views
110
Activity
1w
Reply to Transitions inside ScreenTime Report is not working if phone locked when app is opened.
Can you open a bug report for it ? we reported a lot of issues with DeviceActivityReport views not behaving like regular SwiftUI views, and this would complement those bug reports
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
1w
TimeDataSource .dateRange(endingAt:) won't update
Hello, I'm trying to add a new Live Activity to my app showing a timer to a specific date and time. I thought I could use some TimeDataSource so that the timer would be updated automatically by SwiftUI without relying on Live Activity updates. That's not the case with .dateRange(endingAt:) though. Text(.dateRange(endingAt: targetDate), format: .components(style: .narrow)) Something like this correctly shows the timer exactly how I want it, but it never updates. Other TimeDataSource like .currentDate and .durationOffset(to:) do update automatically, but are not what I'm looking for. Am I missing something? Should I use another formatter to make it work?
Replies
0
Boosts
0
Views
175
Activity
1w
Presenting content on Connected Display not working on iOS 27
I have an app that displays different content on a connected display (following this guide). It's working fine on iOS 26 but no longer is working in iOS 27 (both dev betas) + the latest SDKs. I tried to find any update notes but I couldn't find anything so I'm not sure if I'm doing something wrong or if it's an actual bug. I was able to simplify it down to the simplest case here: import SwiftUI // App Delegate to setup the scene delegate @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { print(Calling didFinishLaunchingWithOptions) return true } func application(_: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options _: UIScene.ConnectionOptions) -> UISceneConfiguration { print(Calling configurationForConnecting) let sceneConfig = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) sceneConfig.delegateCl
Replies
2
Boosts
0
Views
158
Activity
1w
Reply to Labels in toolbar menu get wrapped when upgrading from iOS 18 to 26
Hello @1066, Thank you for your post. In iOS 26, this is controlled by the system, however, in the 27 releases, SwiftUI introduces new toolbar APIs to control how these items are displayed as your app resizes. Use visibilityPriority modifier to keep important groups of toolbar items visible. Use toolbarOverflowMenu to permanently place lower priority toolbar items into the overflow menu. User topBarPinnedTrailing to pin needed toolbar items to the trailing edge at all times. Check out the WWDC26 What’s new in SwiftUI session for more new updates which might relevant to your project.  Travis
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
1w
Labels in toolbar menu get wrapped when upgrading from iOS 18 to 26
When upgrading an app from iOS 18 to iOS 26, some labels in a toolbar menu get wrapped unexpectedly. The issue can be reproduced through the sample below, which contains this label : Envoyer une réaction On iPhone with iOS 18, the label is displayed on 1 line. But on iPhone with iOS 26, the label is displayed on 2 lines. No improvement was obtained through these modifiers : .lineLimit, .frame and .fixedSize . . How to avoid this unnecessary label wrapping that disrupts the readability ? . . import SwiftUI struct SampleView: View { var body: some View { NavigationStack { Color.clear .toolbar { ToolbarItem { Menu { Button(action: {}) { Label(Envoyer une réaction, systemImage: envelope) } } label: { Image(systemName: ellipsis) } } } } } } #Preview { SampleView() }
Replies
2
Boosts
0
Views
137
Activity
1w
Reply to SwiftUI 6 AttributeGraph warnings in console
Thanks for the very interesting post. I’m a little confused and I’m guessing too much for a Monday I think. The reason you are seeing this AttributeGraph: cycle detected warning comes down to how Swift Concurrency, I think. However because your code is a minimal reproducible example, the correct fix depends on what you are actually doing between isWorking = true and isWorking = false in your real app. I don’t see how that code will produce anything. In SwiftUI, Button actions are implicitly isolated to the @MainActor. When you create a Task { ... } inside a button action, that Task should inherits the MainActor. Because your Task is already on the MainActor, calling await MainActor.run { ... } does not actually suspend or switch threads. It should executes synchronously. You are setting isWorking = true and then instantly setting isWorking = false in the exact same runloop without any code or anything to run between them? If your real app does some heavy calculations or data parsing between the two s
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
1w
SwiftUI 6 AttributeGraph warnings in console
On a MacBook Air M4 running macOS Sequoia 15.7.7, the following tiny code does warn inside the Xcode 26.3. Here is the whole console output: === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 110216 === === AttributeGraph: cycle detected through attribute 110216 === === AttributeGraph: cycle detected through attribute 110284 === === AttributeGraph: cycle detected through attribute 110284 === === AttributeGraph: cycle detected through attribute 110216 === === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 109592 === === AttributeGraph: cycle detected through attribute 110216 === Here is the full code: import SwiftUI @main struct myApp: App { var body: some Scene { WindowGroup { BaseView() } } } struct BaseView: View { @State private var isWorking: Bool = false var body: some View { Button(Go) { Task { // Attr
Topic: UI Frameworks SubTopic: SwiftUI
Replies
4
Boosts
0
Views
159
Activity
1w
iOS 27 ImagePlaygroundViewController.Delegate not working?
In the WWDC 2026 sessions it was called out in code that the helper functions would still work, however they don't seem to be working either inside a UIViewRepresentable, nor as a UIKit View as below (also tried as a sheet, to no avail). Otherwise it works. Is there something else I'm missing? import SwiftUI import ImagePlayground @available(iOS 27.0, *) final class ImagePlaygroundPopupController: UIViewController { var sourceImage: UIImage var prompt: String var onComplete: (URL) -> Void var onCancel: () -> Void private var didPresent = false private var playgroundVC: ImagePlaygroundViewController? init( sourceImage: UIImage, prompt: String, onComplete: @escaping (URL) -> Void, onCancel: @escaping () -> Void ) { self.sourceImage = sourceImage self.prompt = prompt self.onComplete = onComplete self.onCancel = onCancel super.init(nibName: nil, bundle: nil) view.backgroundColor = .clear } required init?(coder: NSCoder) { fatalError(init(coder:) has not been implemented) } override func viewD
Replies
0
Boosts
0
Views
137
Activity
1w
WorldAnchor instantly removed when SpatialTrackingSession and ARKitSession run together
Bug: When SpatialTrackingSession and ARKitSession + WorldTrackingProvider are running concurrently, any WorldAnchor added via WorldTrackingProvider.addAnchor() triggers .added followed immediately by .removed—without any user call to removeAnchor(). The anchor never persists in allAnchors. import SwiftUI import RealityKit import ARKit struct ImmersiveView: View { @State private var worldTracking: WorldTrackingProvider? @State private var arSession: ARKitSession? @State private var processWorldTrackingUpdatesTask: Task? var body: some View { RealityView { content in let configuration = SpatialTrackingSession.Configuration(tracking: [.world]) if let unavailableCapabilities = await SpatialTrackingSession().run(configuration) { if unavailableCapabilities.anchor.contains(.world) { fatalError(World tracking is not available on this device.) } } let worldTracking = WorldTrackingProvider() let arSession = ARKitSession() self.arSession = arSession try! await arSession.run([worldTracking]) self.worldTracking =
Replies
4
Boosts
0
Views
305
Activity
2w
Reply to How to get Ask Siri context menu button
Hello @Jordan, From WWDC26 session: Modernize your UIKit app Menus will automatically display this item when there's content relevant for Siri. To provide more relevant information specific to your app, use the new View Annotations API. With it you can annotate specific views with AppEntities. For SwiftUI: Use .appEntityIdentifier() on something like each cell inside of a ForEach: ForEach(items) { item in CellView(item: item) .appEntityIdentifier( EntityIdentifier(for: MyItemEntity.self, identifier: item.id) ) .contextMenu { ... } } This is the View Entity Annotation API from session 343: Explore advanced App Intents features for Siri and Apple Intelligence Note: MyItemEntity must conform to AppEntity with a persistent identifier. For more information see: App Intents I hope this helps!  Travis
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
2w
Reply to Interface Builder is barely usable
IB is such a perfect tool to visually build a layout, I am very sad to see it so neglected. Fully agree. Doing in code makes is so hard to understand and quasi impossible to maintain. And I don't find SwiftUI so good to design precise UI (where many items need to be precisely positioned). I compared Xcode 26.3 and 16.4 : 26.3 takes between 9 and 12s to open the first view in IB, instead of 6s. Would be really interesting to know what it does differently.
Replies
Boosts
Views
Activity
2w