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

Posts under SwiftUI tag

200 Posts

Post

Replies

Boosts

Views

Activity

Adaptive Layouts iOS 27
I was experimenting with existing APIs using a NavigationSplitView and noticed that in the SwiftUI preview, resizing causes the component to switch between the content view and the sidebar. However, with the new DeviceHub tool, the app doesn’t detect the new size and stays in the content view. Is this expected? I would expect Navigation Split View to handle size changes automatically. Is this expected behaviour? FB23340323
3
0
135
48m
iOS 27 beta 1: .scrollEdgeEffectStyle(.soft) renders fully transparent above safeAreaBar
Feedback ID: FB23086400 On iOS 27 beta 1, .scrollEdgeEffectStyle(.soft, for: .top) on a List underneath a custom .safeAreaBar(edge: .top) no longer renders the progressive fade-blur. The top edge is fully transparent — scrolled rows pass under the bar with no visual treatment at all, as if scrollEdgeEffectDisabled() had been applied. What I've verified so far: .hard renders correctly in the exact same hierarchy; only .soft is affected. The same binary works correctly on iOS 26.x Xcode preview. I'm building with Xcode 26.3 (iOS 26 SDK). Minimal reproduction: import SwiftUI struct EdgeEffectRepro: View { enum Style: String, CaseIterable, Identifiable { case automatic, soft, hard var id: Self { self } var value: ScrollEdgeEffectStyle { switch self { case .automatic: .automatic case .soft: .soft case .hard: .hard } } } @State private var style: Style = .soft @State private var useSystemBarOnly = false var body: some View { NavigationStack { List(0..<60, id: \.self) { i in Text("Row \(i)") .frame(maxWidth: .infinity, alignment: .leading) .listRowBackground( i.isMultiple(of: 2) ? Color.orange.opacity(0.45) : Color.teal.opacity(0.45) ) } .scrollIndicators(.hidden) .scrollEdgeEffectStyle(style.value, for: .top) .safeAreaBar(edge: .top) { if !useSystemBarOnly { VStack(spacing: 8) { HStack { Text("Custom Top Bar") .font(.system(size: 28, weight: .bold)) Spacer() } HStack { Text("Second row (e.g. date range picker)") .font(.caption) .foregroundStyle(.secondary) Spacer() } } .padding(.horizontal) } } .safeAreaInset(edge: .bottom) { VStack(spacing: 8) { Picker("Edge effect style", selection: $style) { ForEach(Style.allCases) { Text($0.rawValue).tag($0) } } .pickerStyle(.segmented) Toggle("System bar only (control group)", isOn: $useSystemBarOnly) .font(.caption) } .padding() .background(.regularMaterial) } .navigationTitle("EdgeEffect Repro") .navigationBarTitleDisplayMode(.inline) } } } Steps: run on iOS 27 beta 1, set the picker to soft, scroll rows under the bar. Expected: fade-blur as on iOS 26. Actual: fully transparent. Switch to hard: renders fine.
3
6
456
17h
Did VisionOS27 get the LazyVGrid Performance Updates?
Did VisionOS get the LazyVGrid Performance Updates that other platforms received? I’m observing that a LazyVGrid that works well on iPhone, iPad, and Mac appears to hitch and jitter as cells exit and renter the lazyVGrid on VisionOS. It really feels like it did not get the same behavior changes as the other platforms. I observe the scrollbar expands as cells leave the top of the grid, and each “exit” of a row seems to cause a hitch. I’ve got rigidly defined cell frames, rigidly defined columns. I don’t think any cells frames are being invalidated during scroll… (there’s no way to check this with instruments, right?) I‘ve made several analysis passes myself and threw the Xcode Agent with Codex at it just to scan for stuff, but it’s starting to just guess at things. Any known issues with VisionOS?
2
0
29
18h
Bug: Xcode 26.2 wants `ENABLE_DEBUG_DYLIB`: How do I enable that in `Package.swift`?
Xcode tells me Previewing in executable targets now requires a new build layout for unoptimized builds. Either set ENABLE_DEBUG_DYLIB to YES for this target, or break out your preview code into a separate framework with its own scheme. How do enable that in Package.swift. swiftSettings don't work (.define and unsafeFlags with -D ...). Creating a library product that the executable then depends on doesn't help either. I have two targets, one is an executable target. The #Preview macro is in the non-executable target.
4
2
447
19h
How Did Apple Create the Fitness App Awards Animation?
Open your Apple Fitness app, I am facinated by the animation of the Awards screen, it is so smooth. Any idea how this was transiton created from a Grid/CollectionView to a RealityView? I assume the interative badge is a RealityView with a 3D model in there, but how the hell the transition was so smooth from the parent list screen to the detail screen.
0
0
25
20h
How can a SwiftUI drag provide the actual file URL of an existing file on macOS (as NSOutlineView does)?
I'm dragging existing files from a SwiftUI List (a search result list in a sandboxed, document-based Mac app), and I want drop targets to receive the actual file URL — the same behavior as AppKit's NSOutlineView with outlineView(_:pasteboardWriterForItem:) returning an NSURL: the Finder copies the file, browsers load it, and text views insert its path. My current implementation is Transferable-based: FileRepresentation(exportedContentType: .data) { item in SentTransferredFile(item.fileURL, allowAccessingOriginalFile: true) } .suggestedFileName(\.fileURL.lastPathComponent) With this, what receivers get is a temporary copy in the app's own container (Caches/com.apple.SwiftUI.Drag-<UUID>/), not the actual file URL — despite allowAccessingOriginalFile: true. Dropping on the Finder or onto an application icon works through the copy, but receivers that interpret the URL itself — a browser window, or a text view that inserts the dropped file's path — see the temporary container path. Note that the dragged files live inside a folder the user has opened as a document (the app is NSDocument-based), so the app already holds security-scoped access to them. Alternatives don't help either: DataRepresentation(exportedContentType: .fileURL) returning the URL bytes of the actual file: the pasteboard data is likewise replaced with the copy's URL, and moreover, drops onto application icons (e.g. Safari in the Dock) are no longer accepted at all. onDrag with NSItemProvider(object: url as NSURL): same substitution. I've already filed this as FB23578716, with detailed reproduction steps and drag-pasteboard dumps. My questions: Is there any way in current SwiftUI (macOS 26/27 SDK) to put the real file URL of an existing file on the drag pasteboard? Is the rewriting to a temporary copy intended behavior (for sandbox safety), or a bug? If it's intended, is embedding an AppKit view that calls beginDraggingSession(with:event:source:) with an NSURL pasteboard writer the recommended workaround for now? It does write the real URL, but making it coexist with List's selection and click handling has proven fragile. Environment: macOS: macOS 27 Beta 2 / Version 26.5.2 Xcode: Version 27.0 Beta 2 App Sandbox enabled
1
0
67
1d
Pass data to an @Observable model
Overview I have a navigation split view. The detail view contains a model now this model depends on id from the parent view. Questions How can I pass data from the parent view and yet create the view in the detail view? Or should I be pass the model from the parent view, but the problem is the parent view needs to persist model. Or is there a better approach?
6
0
176
1d
NavigationStack has no animations or back gesture in macOS
When running a native macOS app using SwiftUI and a NavigationStack, clicking any links causes the contents of the stack to change immediately with no animation, and you can't use the usual two-finger swipe gesture to go back. The behavior is correct when running it as a Mac Catalyst app, you get the animated transitions when navigating, and swiping works. Minimal Example: (put this directly inside the WindowGroup) NavigationStack { VStack { NavigationLink { Rectangle().foregroundStyle(.red) } label: { Text("Button") } } }
0
0
29
1d
SwiftUI Slider onEditingChanged is unreliable on iOS 26
For information I stumbled upon a regression with SwiftUI Slider on iOS 26. Its onEditingChanged closure might be called twice when interaction ends, with a final Boolean incorrect value of true provided to the closure. As a result apps cannot reliably rely on this closure to detect when an interaction with the slider starts or ends. I filed a feedback under FB20283439 (iOS 26.0 regression: Slider onEditingChanged closure is unreliable).
8
10
630
2d
Cannot download voices in the iOS 26.5 Simulator
The issue can be reproduced as follows : Launch the iOS 26.5 Simulator. Go to the Settings app. Tap Accessibility. Tap Spoken Content. Turn on Speak Selection. Tap Voices. An empty view gets opened, in which no language can be selected. How can voices be downloaded in the iOS 26.5 Simulator ? Note: There is not such issue in the iOS 18.5 Simulator. Note: There is not such issue in a real iOS 26.5 Device.
2
0
121
5d
requestReview() prompting repeatedly
We're getting user reports that the App Store rating prompt appears repeatedly — one user says they're prompted roughly every day, and that they still get the prompt after they've already left a rating. This contradicts the documented behavior, so I want to check whether others are seeing the same thing or whether there's a known regression. What the docs say should happen The system limits display to 3 occurrences per app within a 365-day period. For a user who has already rated/reviewed, StoreKit should only display again if the app version is new and more than 365 days have passed since their previous review. Has anyone else experience it?
0
0
124
5d
TextField format, integer limits and fractions not applied
Hi Apple-Team, the format of a text field, in my case a percentage with one decimal place, is not applied when a button is pressed and the view is exited using dismiss. It is only used when another field receives focus. A button is not a focusable object, and this is a problem. This allows you to specify more decimal places, resulting in a saved value with unwanted decimal places. It's even worse when you specify integer limits and the value exceeds the limit. Do you always have to check the value before saving it? What's the point of having a format then? Some example images: The items in the list have a fraction limit of 8. The field has integer limit 2 and 1 fraction. When focusing a different field the format is applied. Here the code I used: struct Item: Identifiable, Hashable { var id: Int var value: Double } struct WrongFractionsListView: View { @State private var items: [Item] = [ Item(id: 1, value: 0.225), Item(id: 2, value: 0.377), Item(id: 3, value: 0.241)] enum ItemTransfer: Hashable { case new } var body: some View { List { ForEach(items) { item in HStack { Text("\(item.id)") Spacer() Text("\(item.value, format: .percent.precision(.fractionLength(8)))") } } } .navigationDestination(for: ItemTransfer.self) { _ in WrongFractionsEditorView(items: $items) } .toolbar{ ToolbarItem(placement: .topBarTrailing) { NavigationLink(value: ItemTransfer.new) { Image(systemName: "plus") } } } } } #Preview { NavigationStack { WrongFractionsListView() } } struct WrongFractionsEditorView: View { @Environment(\.dismiss) var dismiss @State private var percentValue: Double = 0 @State private var testValue: String = "" @Binding var items: [Item] var body: some View { Form { TextField("(%)", value: $percentValue, format: .percent.precision(.integerAndFractionLength(integerLimits: 0...2, fractionLimits: 0...1))) .keyboardType(.decimalPad) TextField("Just for Focus", text: $testValue) } .navigationTitle("Percent Fractions") .toolbar{ ToolbarItem(placement: .topBarTrailing) { Button { saveAndClose() } label: { Image(systemName: "checkmark") } } } } private func saveAndClose() { let max = items.max { $0.id < $1.id}!.id let item: Item = .init(id: max+1, value: percentValue) items.append(item) dismiss() } } #Preview { @Previewable @State var items: [Item] = [ Item(id: 1, value: 0.225), Item(id: 2, value: 0.377), Item(id: 3, value: 0.241)] NavigationStack { WrongFractionsEditorView(items: $items) } } How can I fix this? Thank you Christian
2
0
111
5d
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.delegateClass = WindowSceneDelegate.self return sceneConfig } } // Scene delegate that sets up the view class WindowSceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) { print("Calling scene(willConnectTo:) with role \(scene.session.role)") guard let windowScene = (scene as? UIWindowScene) else { return } let window = UIWindow(windowScene: windowScene) if scene.session.role == .windowExternalDisplayNonInteractive { window.rootViewController = UIHostingController(rootView: ExternalDisplay()) } else { window.rootViewController = UIHostingController(rootView: ContentView()) } self.window = window window.makeKeyAndVisible() } } struct ExternalDisplay: View { var body: some View { Text("Other World!") } } struct ContentView: View { var body: some View { Text("Hello, world!") } } I also have my Info showing "Enable Multiple Scenes" set to true. I can screen mirror this app to my Mac (same result with an Apple TV). On iOS 26, on my iPhone, I'd see "Hello World!" and on the connected display, I'd see "Other World!". On iOS 27, this is no longer the case. On my connected display, I just see "Hello World". I'm trying to figure out if I've missed something or if this is a dev beta bug.
2
0
124
6d
How to style SwiftUI sidebar row selections like native macOS apps (Finder, Photos)
https://gist.github.com/MorusPatre/4b1e93973c3e4133794512fd7eefee48 This Is a Test App to find out how to actually achieve the exact sidebar styling Apple uses for Finder, Photos etc. The crucial part is how do I make it so the symbol and name of the selected row use the accent colour with active and inactive styling rather than having the accent colour for the row background? It shouldn't be that complicated I feel like but every AI model (even Claude Fable 5) fails at that and I haven't found apps or videos where that is explained so is that just a classic case of "Apple doesn't want you to know"?
1
0
102
6d
NSApp.activate() does not work with menu bar (background) apps
NSApp(ignoringOtherApps:) is deprecated but there is no other working alternative for menu bar apps. NSApp.activate() does not work when no app windows are active and we want to show a window from a menu bar application. Making it impossible for the app to open a window and make it active. Is it really an intended behavior? Here is a sample project showing the issue: https://github.com/wojciech-kulik/macos-menu-bar-bug Steps to reproduce: Run the app. Focus some other app like Finder or Safari. Click on the app's menu bar icon and select "Open". The app window will appear below the other app's window, instead of being brought to the front. NSApp(ignoringOtherApps: true) works as expected though. I also created a feedback ticket: FB23508310
10
1
163
6d
Tap area of a button differs whether it is in toolbar or not
To compare the tap areas of two similar buttons, the sample below is run in the preview canvas for an iPhone with iOS 26. Button 1 is outside the toolbar, whereas Button 2 is inside the toolbar. When tapping outside Button 1 near its edge, unexpectedly the action is triggered. When tapping inside Button 2 near its edge, unexpectedly the action is not triggered. Why are the tap areas of similar buttons not similar ? How to make a tap area have the edge of the button ? . . import SwiftUI struct SampleView: View { var body: some View { NavigationStack { Button(action: self.action) { Text("Button 1") } .buttonStyle(.glassProminent) .toolbar { ToolbarItem { Button(action: self.action) { Text("Button 2") } .buttonStyle(.glassProminent) } } } } private func action() { print("Action Triggered !") } } #Preview { SampleView() }
0
0
68
1w
Adaptive Layouts iOS 27
I was experimenting with existing APIs using a NavigationSplitView and noticed that in the SwiftUI preview, resizing causes the component to switch between the content view and the sidebar. However, with the new DeviceHub tool, the app doesn’t detect the new size and stays in the content view. Is this expected? I would expect Navigation Split View to handle size changes automatically. Is this expected behaviour? FB23340323
Replies
3
Boosts
0
Views
135
Activity
48m
iOS 27 beta 1: .scrollEdgeEffectStyle(.soft) renders fully transparent above safeAreaBar
Feedback ID: FB23086400 On iOS 27 beta 1, .scrollEdgeEffectStyle(.soft, for: .top) on a List underneath a custom .safeAreaBar(edge: .top) no longer renders the progressive fade-blur. The top edge is fully transparent — scrolled rows pass under the bar with no visual treatment at all, as if scrollEdgeEffectDisabled() had been applied. What I've verified so far: .hard renders correctly in the exact same hierarchy; only .soft is affected. The same binary works correctly on iOS 26.x Xcode preview. I'm building with Xcode 26.3 (iOS 26 SDK). Minimal reproduction: import SwiftUI struct EdgeEffectRepro: View { enum Style: String, CaseIterable, Identifiable { case automatic, soft, hard var id: Self { self } var value: ScrollEdgeEffectStyle { switch self { case .automatic: .automatic case .soft: .soft case .hard: .hard } } } @State private var style: Style = .soft @State private var useSystemBarOnly = false var body: some View { NavigationStack { List(0..<60, id: \.self) { i in Text("Row \(i)") .frame(maxWidth: .infinity, alignment: .leading) .listRowBackground( i.isMultiple(of: 2) ? Color.orange.opacity(0.45) : Color.teal.opacity(0.45) ) } .scrollIndicators(.hidden) .scrollEdgeEffectStyle(style.value, for: .top) .safeAreaBar(edge: .top) { if !useSystemBarOnly { VStack(spacing: 8) { HStack { Text("Custom Top Bar") .font(.system(size: 28, weight: .bold)) Spacer() } HStack { Text("Second row (e.g. date range picker)") .font(.caption) .foregroundStyle(.secondary) Spacer() } } .padding(.horizontal) } } .safeAreaInset(edge: .bottom) { VStack(spacing: 8) { Picker("Edge effect style", selection: $style) { ForEach(Style.allCases) { Text($0.rawValue).tag($0) } } .pickerStyle(.segmented) Toggle("System bar only (control group)", isOn: $useSystemBarOnly) .font(.caption) } .padding() .background(.regularMaterial) } .navigationTitle("EdgeEffect Repro") .navigationBarTitleDisplayMode(.inline) } } } Steps: run on iOS 27 beta 1, set the picker to soft, scroll rows under the bar. Expected: fade-blur as on iOS 26. Actual: fully transparent. Switch to hard: renders fine.
Replies
3
Boosts
6
Views
456
Activity
17h
Did VisionOS27 get the LazyVGrid Performance Updates?
Did VisionOS get the LazyVGrid Performance Updates that other platforms received? I’m observing that a LazyVGrid that works well on iPhone, iPad, and Mac appears to hitch and jitter as cells exit and renter the lazyVGrid on VisionOS. It really feels like it did not get the same behavior changes as the other platforms. I observe the scrollbar expands as cells leave the top of the grid, and each “exit” of a row seems to cause a hitch. I’ve got rigidly defined cell frames, rigidly defined columns. I don’t think any cells frames are being invalidated during scroll… (there’s no way to check this with instruments, right?) I‘ve made several analysis passes myself and threw the Xcode Agent with Codex at it just to scan for stuff, but it’s starting to just guess at things. Any known issues with VisionOS?
Replies
2
Boosts
0
Views
29
Activity
18h
Bug: Xcode 26.2 wants `ENABLE_DEBUG_DYLIB`: How do I enable that in `Package.swift`?
Xcode tells me Previewing in executable targets now requires a new build layout for unoptimized builds. Either set ENABLE_DEBUG_DYLIB to YES for this target, or break out your preview code into a separate framework with its own scheme. How do enable that in Package.swift. swiftSettings don't work (.define and unsafeFlags with -D ...). Creating a library product that the executable then depends on doesn't help either. I have two targets, one is an executable target. The #Preview macro is in the non-executable target.
Replies
4
Boosts
2
Views
447
Activity
19h
How Did Apple Create the Fitness App Awards Animation?
Open your Apple Fitness app, I am facinated by the animation of the Awards screen, it is so smooth. Any idea how this was transiton created from a Grid/CollectionView to a RealityView? I assume the interative badge is a RealityView with a 3D model in there, but how the hell the transition was so smooth from the parent list screen to the detail screen.
Replies
0
Boosts
0
Views
25
Activity
20h
How can a SwiftUI drag provide the actual file URL of an existing file on macOS (as NSOutlineView does)?
I'm dragging existing files from a SwiftUI List (a search result list in a sandboxed, document-based Mac app), and I want drop targets to receive the actual file URL — the same behavior as AppKit's NSOutlineView with outlineView(_:pasteboardWriterForItem:) returning an NSURL: the Finder copies the file, browsers load it, and text views insert its path. My current implementation is Transferable-based: FileRepresentation(exportedContentType: .data) { item in SentTransferredFile(item.fileURL, allowAccessingOriginalFile: true) } .suggestedFileName(\.fileURL.lastPathComponent) With this, what receivers get is a temporary copy in the app's own container (Caches/com.apple.SwiftUI.Drag-<UUID>/), not the actual file URL — despite allowAccessingOriginalFile: true. Dropping on the Finder or onto an application icon works through the copy, but receivers that interpret the URL itself — a browser window, or a text view that inserts the dropped file's path — see the temporary container path. Note that the dragged files live inside a folder the user has opened as a document (the app is NSDocument-based), so the app already holds security-scoped access to them. Alternatives don't help either: DataRepresentation(exportedContentType: .fileURL) returning the URL bytes of the actual file: the pasteboard data is likewise replaced with the copy's URL, and moreover, drops onto application icons (e.g. Safari in the Dock) are no longer accepted at all. onDrag with NSItemProvider(object: url as NSURL): same substitution. I've already filed this as FB23578716, with detailed reproduction steps and drag-pasteboard dumps. My questions: Is there any way in current SwiftUI (macOS 26/27 SDK) to put the real file URL of an existing file on the drag pasteboard? Is the rewriting to a temporary copy intended behavior (for sandbox safety), or a bug? If it's intended, is embedding an AppKit view that calls beginDraggingSession(with:event:source:) with an NSURL pasteboard writer the recommended workaround for now? It does write the real URL, but making it coexist with List's selection and click handling has proven fragile. Environment: macOS: macOS 27 Beta 2 / Version 26.5.2 Xcode: Version 27.0 Beta 2 App Sandbox enabled
Replies
1
Boosts
0
Views
67
Activity
1d
Pass data to an @Observable model
Overview I have a navigation split view. The detail view contains a model now this model depends on id from the parent view. Questions How can I pass data from the parent view and yet create the view in the detail view? Or should I be pass the model from the parent view, but the problem is the parent view needs to persist model. Or is there a better approach?
Replies
6
Boosts
0
Views
176
Activity
1d
NavigationStack has no animations or back gesture in macOS
When running a native macOS app using SwiftUI and a NavigationStack, clicking any links causes the contents of the stack to change immediately with no animation, and you can't use the usual two-finger swipe gesture to go back. The behavior is correct when running it as a Mac Catalyst app, you get the animated transitions when navigating, and swiping works. Minimal Example: (put this directly inside the WindowGroup) NavigationStack { VStack { NavigationLink { Rectangle().foregroundStyle(.red) } label: { Text("Button") } } }
Replies
0
Boosts
0
Views
29
Activity
1d
SwiftUI Slider onEditingChanged is unreliable on iOS 26
For information I stumbled upon a regression with SwiftUI Slider on iOS 26. Its onEditingChanged closure might be called twice when interaction ends, with a final Boolean incorrect value of true provided to the closure. As a result apps cannot reliably rely on this closure to detect when an interaction with the slider starts or ends. I filed a feedback under FB20283439 (iOS 26.0 regression: Slider onEditingChanged closure is unreliable).
Replies
8
Boosts
10
Views
630
Activity
2d
Cannot download voices in the iOS 26.5 Simulator
The issue can be reproduced as follows : Launch the iOS 26.5 Simulator. Go to the Settings app. Tap Accessibility. Tap Spoken Content. Turn on Speak Selection. Tap Voices. An empty view gets opened, in which no language can be selected. How can voices be downloaded in the iOS 26.5 Simulator ? Note: There is not such issue in the iOS 18.5 Simulator. Note: There is not such issue in a real iOS 26.5 Device.
Replies
2
Boosts
0
Views
121
Activity
5d
requestReview() prompting repeatedly
We're getting user reports that the App Store rating prompt appears repeatedly — one user says they're prompted roughly every day, and that they still get the prompt after they've already left a rating. This contradicts the documented behavior, so I want to check whether others are seeing the same thing or whether there's a known regression. What the docs say should happen The system limits display to 3 occurrences per app within a 365-day period. For a user who has already rated/reviewed, StoreKit should only display again if the app version is new and more than 365 days have passed since their previous review. Has anyone else experience it?
Replies
0
Boosts
0
Views
124
Activity
5d
onChange(of:initial:_:) changes when same value assigned
Overview When calling onChange(of:initial:_:) with initial as true, closure called even when the value assigned is the same as previous value (not just the first time, subsequently too). However when initial value is false it is called only when value changes. Questions Is this a bug? Am I missing something?
Replies
1
Boosts
0
Views
173
Activity
5d
TextField format, integer limits and fractions not applied
Hi Apple-Team, the format of a text field, in my case a percentage with one decimal place, is not applied when a button is pressed and the view is exited using dismiss. It is only used when another field receives focus. A button is not a focusable object, and this is a problem. This allows you to specify more decimal places, resulting in a saved value with unwanted decimal places. It's even worse when you specify integer limits and the value exceeds the limit. Do you always have to check the value before saving it? What's the point of having a format then? Some example images: The items in the list have a fraction limit of 8. The field has integer limit 2 and 1 fraction. When focusing a different field the format is applied. Here the code I used: struct Item: Identifiable, Hashable { var id: Int var value: Double } struct WrongFractionsListView: View { @State private var items: [Item] = [ Item(id: 1, value: 0.225), Item(id: 2, value: 0.377), Item(id: 3, value: 0.241)] enum ItemTransfer: Hashable { case new } var body: some View { List { ForEach(items) { item in HStack { Text("\(item.id)") Spacer() Text("\(item.value, format: .percent.precision(.fractionLength(8)))") } } } .navigationDestination(for: ItemTransfer.self) { _ in WrongFractionsEditorView(items: $items) } .toolbar{ ToolbarItem(placement: .topBarTrailing) { NavigationLink(value: ItemTransfer.new) { Image(systemName: "plus") } } } } } #Preview { NavigationStack { WrongFractionsListView() } } struct WrongFractionsEditorView: View { @Environment(\.dismiss) var dismiss @State private var percentValue: Double = 0 @State private var testValue: String = "" @Binding var items: [Item] var body: some View { Form { TextField("(%)", value: $percentValue, format: .percent.precision(.integerAndFractionLength(integerLimits: 0...2, fractionLimits: 0...1))) .keyboardType(.decimalPad) TextField("Just for Focus", text: $testValue) } .navigationTitle("Percent Fractions") .toolbar{ ToolbarItem(placement: .topBarTrailing) { Button { saveAndClose() } label: { Image(systemName: "checkmark") } } } } private func saveAndClose() { let max = items.max { $0.id < $1.id}!.id let item: Item = .init(id: max+1, value: percentValue) items.append(item) dismiss() } } #Preview { @Previewable @State var items: [Item] = [ Item(id: 1, value: 0.225), Item(id: 2, value: 0.377), Item(id: 3, value: 0.241)] NavigationStack { WrongFractionsEditorView(items: $items) } } How can I fix this? Thank you Christian
Replies
2
Boosts
0
Views
111
Activity
5d
Does SwiftUI pass views via the preference and environment, if so, how?
I am under the assumption that SwiftUI does pass views via preference atleast (navigationDestination, toolbar, sheet, alerts, popover etc.,). How does it maintain view identity and does it wrap the passing view in AnyView or internally it uses type inference magic, that is not available to us?. If it does not, then how does it pass them instead ?
Replies
0
Boosts
0
Views
62
Activity
5d
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.delegateClass = WindowSceneDelegate.self return sceneConfig } } // Scene delegate that sets up the view class WindowSceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) { print("Calling scene(willConnectTo:) with role \(scene.session.role)") guard let windowScene = (scene as? UIWindowScene) else { return } let window = UIWindow(windowScene: windowScene) if scene.session.role == .windowExternalDisplayNonInteractive { window.rootViewController = UIHostingController(rootView: ExternalDisplay()) } else { window.rootViewController = UIHostingController(rootView: ContentView()) } self.window = window window.makeKeyAndVisible() } } struct ExternalDisplay: View { var body: some View { Text("Other World!") } } struct ContentView: View { var body: some View { Text("Hello, world!") } } I also have my Info showing "Enable Multiple Scenes" set to true. I can screen mirror this app to my Mac (same result with an Apple TV). On iOS 26, on my iPhone, I'd see "Hello World!" and on the connected display, I'd see "Other World!". On iOS 27, this is no longer the case. On my connected display, I just see "Hello World". I'm trying to figure out if I've missed something or if this is a dev beta bug.
Replies
2
Boosts
0
Views
124
Activity
6d
How to style SwiftUI sidebar row selections like native macOS apps (Finder, Photos)
https://gist.github.com/MorusPatre/4b1e93973c3e4133794512fd7eefee48 This Is a Test App to find out how to actually achieve the exact sidebar styling Apple uses for Finder, Photos etc. The crucial part is how do I make it so the symbol and name of the selected row use the accent colour with active and inactive styling rather than having the accent colour for the row background? It shouldn't be that complicated I feel like but every AI model (even Claude Fable 5) fails at that and I haven't found apps or videos where that is explained so is that just a classic case of "Apple doesn't want you to know"?
Replies
1
Boosts
0
Views
102
Activity
6d
NSApp.activate() does not work with menu bar (background) apps
NSApp(ignoringOtherApps:) is deprecated but there is no other working alternative for menu bar apps. NSApp.activate() does not work when no app windows are active and we want to show a window from a menu bar application. Making it impossible for the app to open a window and make it active. Is it really an intended behavior? Here is a sample project showing the issue: https://github.com/wojciech-kulik/macos-menu-bar-bug Steps to reproduce: Run the app. Focus some other app like Finder or Safari. Click on the app's menu bar icon and select "Open". The app window will appear below the other app's window, instead of being brought to the front. NSApp(ignoringOtherApps: true) works as expected though. I also created a feedback ticket: FB23508310
Replies
10
Boosts
1
Views
163
Activity
6d
How to change the color of the native back button
How do I change the color of the native back button that is added automatically with NavigationSplitView? I have tried a lot of different methods, but I can't find out how to change its color to a custom color instead of just black.
Replies
0
Boosts
0
Views
94
Activity
1w
Tap area of a button differs whether it is in toolbar or not
To compare the tap areas of two similar buttons, the sample below is run in the preview canvas for an iPhone with iOS 26. Button 1 is outside the toolbar, whereas Button 2 is inside the toolbar. When tapping outside Button 1 near its edge, unexpectedly the action is triggered. When tapping inside Button 2 near its edge, unexpectedly the action is not triggered. Why are the tap areas of similar buttons not similar ? How to make a tap area have the edge of the button ? . . import SwiftUI struct SampleView: View { var body: some View { NavigationStack { Button(action: self.action) { Text("Button 1") } .buttonStyle(.glassProminent) .toolbar { ToolbarItem { Button(action: self.action) { Text("Button 2") } .buttonStyle(.glassProminent) } } } } private func action() { print("Action Triggered !") } } #Preview { SampleView() }
Replies
0
Boosts
0
Views
68
Activity
1w
swipeaction background color
With the new .swipeActions introduced in WWDC26, is there any way to give those buttons a background color? I don't mean tinting the button. But the background they appear on.
Replies
0
Boosts
0
Views
63
Activity
1w