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

Mac Catalyst: disabled SwiftUI toolbar buttons turn into pills and don’t update their state
Hi everyone, we’ve been fighting with disabled toolbar buttons in our Mac Catalyst app and wanted to check whether others are seeing the same thing, or whether we’re missing something. Our toolbar lives in a SwiftUI NavigationStack, so Catalyst bridges it into the window’s NSToolbar. Enabled buttons look and work great: native buttons with a round 36 × 36 pt glass. But as soon as a button uses .disabled(_:), things fall apart: It turns into a wider pill. A button that is disabled when it appears becomes an image item instead of a button (NSToolbarImageView with a UIImage), and its glass grows to 47 × 36 pt. Its state doesn’t update. Toggling .disabled(_:) doesn’t reach the existing toolbar item. It only changes if we give the ToolbarItem a new id, which then brings back the pill. Disabling the NSToolbarItem ourselves doesn’t stick. UIKit revalidates the toolbar whenever any item changes, and copies the bar button’s enabled state back over ours. Drawing our own image to fix the shape crashed AppKit (“Unable to install constraint on view”) as soon as the item switched back to enabled. For now we keep the SwiftUI button enabled on the Mac and disable the native NSToolbarItem ourselves. We find the toolbar via NSToolbar.willAddItemNotification and use KVO to put the state back whenever UIKit overrides it. It works, but it feels like it shouldn’t be necessary. Here’s a minimal example: struct ContentView: View { @State private var canUndo = false var body: some View { NavigationStack { Button("Toggle") { canUndo.toggle() } .toolbar { ToolbarItem(placement: .topBarLeading) { Button("Undo", systemImage: "arrow.uturn.backward") {} .labelStyle(.iconOnly) .disabled(!canUndo) } } } } }Seen on macOS 27.2 and 26.7.1, Xcode 27.2. Filed as FB25597608. Is there a supported way to get a disabled toolbar button that stays a normal native button? Any hints are very welcome. Thanks!
0
0
52
2d
SwiftUI TabView with a .prominent tab exhibits unexpected rendering behavior during iPhone Duo display transitions
Hi Apple Support Team, I would like to report an iPhone Duo-specific regression that appears in iOS 27.2.1. The same application behaves correctly on iOS 27.1, and I have been able to reproduce the issue consistently using a minimal sample application. When running the application on iPhone Duo, transitioning from the outer display to the inner display while the device is opened in landscape orientation results in unexpected UI rendering. Specifically, a large arc-shaped visual element associated with a tab configured with the .prominent role appears on screen after the transition. In addition to the rendering issue, we have observed unexpected UI presentation behavior during these display transitions when a tab is assigned the .prominent role. The issue appears to be tied to the .prominent tab role. When all tabs use the default role, the application behaves as expected and neither the rendering issue nor the unexpected UI behavior is observed. A sample application reproducing the issue is attached. Steps to Reproduce Launch the attached sample application on iPhone Duo running iOS 27.2.1. Ensure that one of the tabs is configured with the .prominent role. Start on the outer display. Open the device and transition to the inner display in landscape orientation. Observe the UI during and after the transition. Expected Result TabView should transition cleanly between the outer and inner displays without rendering artifacts or unexpected UI behavior. Actual Result A large arc-shaped visual artifact appears on screen. Unexpected view presentation behavior may occur during the display transition. Multiple animation- and transform-related warnings are logged. // Attached run time logs. Additional Notes Reproducible in both our production application and the attached sample application. The issue appears to be tied to SwiftUI TabView when a tab is assigned the .prominent role. The issue was not observed on iOS 27.1. The issue occurs during transitions between the outer and inner displays on iPhone Duo. Removing the .prominent role eliminates the issue. Could you please let us know whether this is a known issue with SwiftUI TabView and .prominent tabs during iPhone Duo display transitions on iOS 27.2.1? If there is an existing Feedback report, Apple Developer Forums discussion, internal tracking issue, or recommended workaround, we would greatly appreciate any guidance. Screenshots and a sample project are attached. Thank you for your time and assistance. Please let me know if any additional diagnostics, sysdiagnose captures, logs, or sample projects would be helpful. Best regards, Manish
1
0
194
2d
Regression: AxisValueLabel multiLabelAlignment parameter ignored in iOS 27
Hello Apple SwiftUI / Swift Charts Engineering Team, I am writing to report a layout regression regarding Swift Charts in iOS 27. The multiLabelAlignment property on AxisValueLabel has stopped working as expected, whereas it functions perfectly in iOS 26. Bug Description: When configuring custom string values within AxisMarks using AxisValueLabel with multiLabelAlignment: .trailing, the alignment configuration is completely ignored on iOS 27. Labels fail to align text properly to the trailing edge, causing rendering layout issues for multi-line or custom text labels on the Y-axis. This exact same implementation compiles and aligns correctly on iOS 26. Code Snippet to Reproduce: swift struct YAxisAlignmentBugView: View { // data points to render the chart frame let data = [(date: Date(), revenue: 3000.0), (date: Date().addingTimeInterval(10000), revenue: 4000.0)] var body: some View { Chart(data, id: .date) { item in LineMark(x: .value("Date", item.date), y: .value("Revenue", item.revenue)) } .frame(height: 300) .padding() .chartYAxis { AxisMarks(preset: .aligned, position: .trailing, values: [12.0, 600.0, 3000.0, 6000.0]) { value in if let revenue = value.as(Double.self) { // BUG: multiLabelAlignment: .trailing is completely ignored on iOS 27 AxisValueLabel("y-(Int(revenue))", anchor: .leading, multiLabelAlignment: .trailing) } } } } } Steps to Reproduce: Render a Swift Chart containing a .chartYAxis configuration with position: .trailing. Pass a string directly using AxisValueLabel(customText, anchor: .leading, multiLabelAlignment: .trailing). Run the application on an iOS 26 simulator (text aligns properly to the trailing edge). Run the identical application code on an iOS 27 simulator. Expected Behavior: The text inside the AxisValueLabel should honor the multiLabelAlignment: .trailing parameter and align the text strings flush right. Actual Behavior: The multiLabelAlignment layout modifier is ignored on iOS 27, resulting in unexpected default left-alignment of the text strings. Attachments: I have attached screenshots from the Xcode Simulator demonstrating the regression: Please let me know if you need any further diagnostic details. Best regards, Soumyajit Das
3
0
336
2d
Regression: AxisValueLabel anchor parameter ignores .topLeading on iOS 27
Hello Apple SwiftUI / Swift Charts Engineering Team, I am writing to report a layout regression regarding Swift Charts in iOS 27. The anchor property on AxisValueLabel has stopped honoring the .topLeading layout coordinate, whereas it functions perfectly in iOS 26. Bug Description: To prevent the first label on a bottom X-axis from clipping past the left screen edge, a .topLeading anchor is applied. In iOS 27, this specific anchor alignment is completely ignored. The chart falls back to a standard top-center alignment, causing the initial boundary label to clip off-screen. Core Code Snippet to Reproduce: struct XAxisAnchorBugView: View { let dates = [ Calendar.current.date(from: DateComponents(year: 2026, month: 10, day: 1))!, Calendar.current.date(from: DateComponents(year: 2026, month: 10, day: 2))! ] var body: some View { Chart(dates, id: .self) { date in LineMark(x: .value("Date", date), y: .value("Value", 100)) } .frame(height: 300) .padding() .chartXAxis { AxisMarks(preset: .aligned, position: .bottom, values: .stride(by: .day, count: 1)) { value in AxisTick() let currentAnchor: UnitPoint = { guard let currentDate = value.as(Date.self) else { return .top } // BUG: .topLeading layout anchor parameter is completely ignored on iOS 27 return (currentDate == dates.first) ? .topLeading : .top }() AxisValueLabel(format: .dateTime.month(.abbreviated).day(), anchor: currentAnchor) } } } } Steps to Reproduce: Render an X-axis with a .bottom position. Assign anchor: .topLeading strictly to the first axis element's label. Run on an iOS 26 simulator (the first label anchors its top-left corner correctly, preventing edge clipping). Run on an iOS 27 simulator (the .topLeading anchor is ignored, reverting to standard top-center alignment). Expected Behavior: AxisValueLabel should position its layout bounding box using the .topLeading anchor point when specified. Actual Behavior: The layout engine ignores the .topLeading parameter on iOS 27, causing the boundary text to shift left and clip. Attachments: I have attached Xcode Simulator screenshots demonstrating this regression: Best regards, Soumyajit Das
3
0
361
2d
How to handle all the core AppleEvents
Glancing through the APIs, SwiftUI can handle the open app, reopen app, open doc, and quit core events (with the “aevt” suite ID). What about the print doc and open content events? If there are no hooks (yet), how can I implement them the traditional way without clashing with SwiftUI?
2
0
815
2d
iPhone Duo Unfolded Safe Areas
Hi, my app is currently built on Xcode 27.1 I am working on upgrading to Xcode 27.2 We have a regression issue whereby, the top safeArea is 82 despite the vertical bar being opted in and active. This only happens on unfolded landscape. Our right safeArea is 0 for the window and is 84 for the view safeArea. Both window and view safeAreas have the top safe area of 82 though. We would like to know what could be the cause behind the top safeArea being activated. Note: this is not an issue for iOS 27.1
2
0
206
3d
SwiftUI Architecture Guide
Application Types Applications are divided into Document-based and Library-based. A document-based application stores user data in individual, standalone files. Users manually name and organize those files in a local system or synced cloud storage such as iCloud. The software typically opens multiple windows for different projects. This framing is for standalone, complex files that need to be shared, exported, or handled independently. A library-based application manages data in one unified, central repository, locally or through remote cloud databases. Spotify, Netflix, and Notion are the examples shown. The file system is hidden; updates are saved automatically in real time; and a single window supports browsing, search, and access to the synchronized data collection from any device. Model Types Four model types: Data, Domain, Application, and Presentation. Apple Platforms In Apple MVC (AppKit / UIKit), the model branches to Data, Domain, and Presentation. In SwiftUI, Model branches to Data and Domain. Project Structure SwiftUI App Folders Swift Package Folders App Modularization Not every module in a large application needs to be extracted into a separate framework or Swift Package. Logical modularization can also be achieved through a well-organized folder structure within the main project. Introduce separate packages or frameworks only when there is a clear benefit, such as independent reuse, distribution, build isolation or ownership. Avoid unnecessary project and dependency management overhead. State Management & Data Flow Source of truth is “a key concept in SwiftUI”: a single place to store a piece of data, with everywhere else reading the same piece of data. Environment is SwiftUI’s native dependency-injection mechanism. It allows shared dependencies, domain models, and services to be injected at the appropriate view-hierarchy level and accessed where needed without explicit parameter passing or unnecessary coupling. It is described as a tool for managing dependencies and sharing state across the view hierarchy. Domain Model Ownership Domain Models should be owned by the highest relevant SwiftUI view in the hierarchy that defines their context and lifecycle. NavigationStack owns the Domain Models for its navigation context and makes them available to descendant views through @Environment. When a NavigationStack is embedded in a TabView or NavigationSplitView, ownership moves up to the TabView or NavigationSplitView so the models can be shared across tabs or split views. The stated result is clear ownership scope, sharing where needed, and isolation between independent navigation contexts. Previews & UI Testing Environment injection makes SwiftUI Previews and UI Tests easier to configure by allowing real Domain Models to be replaced with mock or dummy instances. Views can be tested independently with controlled data and predictable states, without requiring real services, network requests, or application setup. Domain and Data Model Examples For a library-based app with remote data. Additional Domain Model Examples E-commerce Catalog, ShoppingCart, OrderHistory, Wishlist Banking MyAccounts, MyCards, MyTransactions, MyInvestments Social Network Feed, Conversations, Notifications, Friends Healthcare MyAppointments, MedicalHistory, Prescriptions, MyHealth Education Courses, MyCourses, Assignments, MyGrades, LearningProgress Real Estate PropertyCatalog, MyProperties, Favorites, Appointments Hotel Booking Destinations, Search, MyBookings, TravelHistory Food Delivery RestaurantCatalog, ShoppingCart, MyOrders, DeliveryTracking Project Management Projects, MyTasks, TeamMembers, Notifications Insurance MyPolicies, MyClaims, Coverage, Documents Smart Home MyHomes, Devices, Automations, EnergyUsage Fitness MyPlans, MyProgress, MyGoals, WorkoutHistory Other Search, Dashboard, Favorites, Notifications, Settings, ActivityHistory, Recommendations, Subscription, DocumentLibrary ViewModel? - MVVM In SwiftUI, the View encapsulates the UI content (body), its state (properties), and its actions or tasks (functions). This is possible because SwiftUI is designed around a declarative, state-driven UI model. In Android and .NET platforms, a separate ViewModel is typically required to hold and manage the View's state. Projects that intoduce ViewModels in SwiftUI add unnecessary architectural complexity, boilerplate, and code duplication; synchronization issues; unclear state ownership; additional lifecycle management; more abstractions; harder debugging; and increased maintenance, without meaningful benefits over SwiftUI's native state management. In UIKit, introducing a separate ViewModel layer is often unnecessary, as UIViewController already serves as the presentation model, handling presentation logic and coordinating the view. Non-UI responsibilities can be delegated to dedicated ModelControllers or Managers, avoiding unnecessary layers and abstractions. Domain Models vs. ViewModels Domain Models are view-independent, while ViewModels are view-dependent. A ViewModel is tightly coupled to the structure, state, and lifecycle of a specific View. Whenever the View code changes, its ViewModel often requires corresponding coding changes, and vice versa, creating additional maintenance and synchronization overhead. Domain Models, on the other hand, represent application context and business functionality independently of the UI. This separation preserves UI independence and allows the same Domain Models to be shared across different screens and platforms, such as iPhone, iPhone Duo, iPad, and macOS, without duplicating or adapting business logic for each View. This makes Domain Models a more scalable and maintainable approach for modern SwiftUI applications, particularly those targeting multiple screen sizes and platforms.
1
0
266
3d
SwiftUI custom focusable view cannot acquire focus programmatically on iPad with a hardware keyboard connected
On iPad, a SwiftUI view using .focusable(interactions: .edit) and .focused($isFocused) cannot acquire focus when a hardware keyboard is already connected. Setting isFocused = true from a button leaves it false. Tapping the view also leaves it unfocused, although the tap is received. Pressing Tab can focus the same view. struct FocusProbeView: View { @FocusState private var isFocused: Bool var body: some View { VStack { Text("Target") .focusable(interactions: .edit) .focused($isFocused) .onTapGesture { print("Target tapped") } Text("isFocused = \(isFocused)") Button("Focus target") { isFocused = true } } .defaultFocus($isFocused, true) } }Steps to reproduce: Run this view on an iPad with a hardware keyboard connected. Tap “Focus target”, then tap “Target”. Observe that isFocused remains false. Press Tab. The target can receive focus through keyboard navigation. Disconnect the keyboard. Restart the app and tap “Focus target” again. isFocused becomes true. Reconnecting the keyboard does not remove that focus. Expected: A visible custom view marked .focusable(interactions: .edit) can receive focus through @FocusState, including when a hardware keyboard is connected. Actual: Programmatic focus fails when the keyboard is already connected. A native TextField tested with the same button and @FocusState does receive focus. Environment: iPad model: MU1V2NF/A; iPadOS version: 26.7.2; Xcode version: 27.2; hardware keyboard: Logi Folio Touch. iPad model: Device Hub iPad Pro 11-inch (M5); iPadOS version: 27.2; Xcode version: 27.2; hardware keyboard: Device Hub.
1
0
230
3d
Inversed swipe gesture in VStack/LazyVStack vs List
I'm using a row swipe to delete gesture in a LazyVStack just the same way I would do in a List and I have to inverse the gesture (from left to right) to allow the Delete button appearing whereas in a List, the left to right swipe gesture works as expected. The following code reveals that unexpected/anti natural behavior. iOS works as expected for the same code. import SwiftUI import Playgrounds struct ContentView: View { var body: some View { VStack { // anti-natural and inconsistent gesture // LazyVStack { // anti-natural and inconsistent gesture // List { // natural gesture HStack { Text("Swipe Test") Spacer() } .padding(10) .frame(height: 40) .background { Color.blue } .swipeActions(edge: .trailing, allowsFullSwipe: false) { Button("Delete", role: .destructive) {} } } } }Setup: Macbook Pro M1 Max / macOS 27.2.1 / Xcode 27.2
0
0
36
3d
Supported way to hide the system time in a full-screen watchOS clock app?
I'm building a standalone watchOS app (SwiftUI, watch-only) whose main screen is its own full-screen clock. The system time in the top-right corner duplicates our clock, so we'd like to hide it while this view is visible. I'd like to know which API is supported for this in an App Store app. What I tried (watchOS 27.2 SDK, Xcode 27.2): .persistentSystemOverlays(.hidden) on the root view and on the scene. The system time stays visible. In a variant with a NavigationStack and a hidden navigation bar, the time was briefly absent after launch, but it came back within about 20 seconds. .statusBarHidden(_:) and .toolbarVisibility(.hidden, for: .statusBar) are marked unavailable on watchOS in the SDK. View._statusBarHidden(_:) hides the system time reliably. In the watchOS SwiftUI interface it is public, available on watchOS since 6.0, and has no @_spi. It inlines to _statusBar(hidden:). However, it's underscored and I can't find documentation for it. Minimal example: struct ClockView: View { var body: some View { MyFullScreenClock() .persistentSystemOverlays(.hidden) // documented, but time remains visible ._statusBarHidden(true) // hides the time, but undocumented } }I've noticed this modifier in shipping open-source watchOS code, for example Home Assistant's watch app (Sources/WatchApp/Home/WatchHomeView.swift). That doesn't tell me whether Apple supports it, though. Questions: Is _statusBarHidden(_:) / _statusBar(hidden:) a supported API for a distributed watchOS app? If not, is there a documented way for a full-screen clock app to hide the system time, or is the system time intentionally always shown in third-party apps? I can share a small sample project that toggles between the documented overlay preference and the underscored modifier. Thanks!
2
0
89
3d
iPhone Duo: Keep app on inner display while hinge is open (like Clock)?
I'm building a night-light app for iPhone Duo. When the device is partly open in tent mode, the lamp starts on the inner display. As soon as I set the phone down on a table, the system moves my window to the outer display, even though the hinge stays open. Apple's Clock app stays on the inner display in the same pose, so it seems possible at the system level. Steps Open iPhone Duo to ~80° (tent). Launch the app on the inner display. Set the device down on a table. Observed (logged from the app) UIHinge.status stays .partiallyOpen (~80°), not .closed. UIDevice.orientation goes portraitUpsideDown → faceDown → landscapeRight. UIScreen.didDisconnectNotification fires and UIScreen.screens drops the inner screen. The window moves to the outer screen (466×678). What I've tried Restricting UISupportedInterfaceOrientations to portrait only Turning on Rotation Lock Reading UIHingeInteraction (read-only, no effect on display routing) Looking at UISceneAccessory.cameraCapture, which only applies with an active capture session and a fully open device Question Is there a supported way for a scene to prefer or stay on the inner display while the hinge isn't closed? If not, I'll file a Feedback Assistant request. iPhone Duo · iOS 27.2 · Xcode 27.2
Topic: UI Frameworks SubTopic: SwiftUI
2
0
89
5d
NavigationSplitView sidebar expansion temporarily oversizes split view and collapses toolbar search
[Submitted as FB25597038] Showing the sidebar in a two-column NavigationSplitView briefly collapses the toolbar search field, even though the window doesn't resize. Search is right-aligned on the detail container using .searchable, ToolbarSpacer(.flexible), and DefaultToolbarItem(kind: .search). The sample below uses static content and the native sidebar toggle and animation. Setting only the sidebar item's collapseBehavior to .useConstraints avoids the issue. It occurred in both recorded baseline expansions and neither expansion with the workaround. Environment macOS 27.2.1 (26B131) Xcode 27.2 (27B52) macOS SDK 27.2 (26B118) Native macOS app, arm64, deployment target macOS 27.0 Initial window: 906 × 600 points Sidebar minimum/ideal/maximum widths: 180/240/360 points Repro Create a new macOS App project named SidebarAnimationRepro, using SwiftUI and Swift. Set the deployment target to macOS 27.0. Replace SidebarAnimationReproApp.swift and ContentView.swift with the code below. Leave usesWorkaround set to false. Build and run. Keep the initial 906-point window width. Click Hide Sidebar and let the transition settle. Click Show Sidebar and watch the search field during expansion. Stop the app, change usesWorkaround to true, and run again. Repeat steps 4–5 to compare the behavior. Expected The split view should stay within the window during sidebar expansion. The search field should stay visible at its normal width without briefly collapsing or disappearing. Actual The split view temporarily grows to 1,146 points while the window stays 906 points wide. Search shrinks from 325 to 36 points and disappears, then returns to its normal size and visibility. The toolbar, search item, and search field remain the same instances, and toolbar item order doesn't change. In one capture, search collapsed about 123 ms after expansion started, returned at 274 ms, and the split view settled at 283 ms. With .useConstraints, the split view stayed at 906 points and search stayed visible at 325 points throughout both hide/show cycles. Screenshots Three frames before, during, and after the sidebar expansion: Sample Code SidebarAnimationReproApp.swift import SwiftUI @main struct SidebarAnimationReproApp: App { var body: some Scene { WindowGroup("Sidebar Animation Repro") { ContentView() } .defaultSize(width: 906, height: 600) } }ContentView.swift import AppKit import SwiftUI struct ContentView: View { @State private var searchText = "" var body: some View { NavigationSplitView { List { Label("Example", systemImage: "folder") } .navigationSplitViewColumnWidth(min: 180, ideal: 240, max: 360) } detail: { Text("Synthetic detail content") .frame(minWidth: 0, maxWidth: .infinity, maxHeight: .infinity) .background { SplitViewAttachment() } .searchable(text: $searchText, placement: .toolbar) .toolbar { ToolbarSpacer(.flexible) DefaultToolbarItem(kind: .search) } } .toolbar(removing: .title) .frame(minWidth: 720, minHeight: 420) } } struct SplitViewAttachment: NSViewRepresentable { func makeNSView(context: Context) -> Attachment { Attachment() } func updateNSView(_ view: Attachment, context: Context) { view.applyWorkaround() } final class Attachment: NSView { private let usesWorkaround = false override func hitTest(_ point: NSPoint) -> NSView? { nil } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() applyWorkaround() } /// The split controller can enter the responder chain after the view enters its window. override func layout() { super.layout() applyWorkaround() } fileprivate func applyWorkaround() { guard usesWorkaround, window != nil else { return } let responders = sequence(first: self as NSResponder, next: \.nextResponder) guard let controller = responders.first(where: { $0 is NSSplitViewController }) as? NSSplitViewController, let sidebar = controller.splitViewItems.first(where: { $0.behavior == .sidebar }), sidebar.collapseBehavior != .useConstraints else { return } sidebar.collapseBehavior = .useConstraints } } }
0
0
49
5d
@FocusedValue from .focusedSceneValue from the Scene Commands
Hi, In iPadOS can we use a .focusedSceneValue, defined from a command/Button inside a Scene, from inside the .command modifier attached to the scene? Like this: @main struct test_focusedSceneValueApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }         .commands {             NavigationCommands()         }     } } struct NavigationCommands: Commands {     @FocusedValue(\.filterAction) var filterAction     var body: some Commands {         CommandMenu("Navigate") {             Button("Test focusedSceneValue") {                 filterAction?()             }             .keyboardShortcut("5")         }     } } struct ContentView: View {     @FocusState var isFiltering: Bool     @State private var focusField: String = "teste field teste"     var body: some View {         TextField("teste focus", text: $focusField)             .focused($isFiltering)             .focusedSceneValue(\.filterAction) {                 print("test successful")                 isFiltering = true             }     } This code is almost the same from the sample code from the documentation, however I can only retrieved nil values from the @FocusedValue and not the defined value. Thanks.
5
0
2.2k
1w
Article Accelerator tutorial: “Dissecting an app’s architecture” doesn’t explain data flow, and ArticleStore isn’t a realistic network simulation
Here's a sharper version. It's blunt about how badly the app is built, but it avoids swearing and insults, because forum moderators remove posts like that. Title: Article Accelerator: an architecture tutorial built on patterns we shouldn't copy Text: The tutorial "Dissecting an app's architecture" promises to show how data flows in and through Article Accelerator: https://developer.apple.com/tutorials/app-dev-training/dissecting-an-apps-architecture For a tutorial whose whole subject is architecture, the sample app is a poor example of it. The article never actually traces the data flow, and the code it describes uses patterns that most SwiftUI guidance tells you to avoid. The "simulated network service" isn't one. The tutorial says ArticleStore simulates a network service. In reality it's a singleton that synchronously loads JSON files from the bundle. It can't be slow, can't fail and can't return partial data, so it simulates none of what makes networking hard. It cannot be turned into an async URLSession call without throwing it away and redesigning the data layer. Views fetch data directly from a singleton. DetailView does private let articles = ArticleStore.shared.articles() as a stored property. There's no @Observable model, no loading state, no error state, and no dependency injection. This makes the views impossible to test with fake data and hides the data flow the tutorial claims to explain. Error handling is print and fatalError. A broken article file is silently skipped with print. An unreadable folder crashes the app. Failing to delete user data also crashes the app. SwiftData setup is inconsistent. The app creates one ModelContainer, then ArticleStateManager creates a separate ModelContext instead of using the container's mainContext. So writes through the manager and @Query reads go through different contexts. On top of that, the environment default for articleStateManager quietly creates a second ModelContainer with try!, so any window that forgets to inject it gets a different container. The structure isn't structured. The tutorial's challenge asks you to sort the Models folder into three categories, but the project puts everything in one flat folder, including ArticleStateManager, which isn't a model at all. Article, the main model, isn't even in it. The key design decision is never explained. Articles live only in memory while user data lives in SwiftData, and views join them by ID. That's a reasonable split, but the tutorial never says so, never explains why, and never addresses what it means for offline support, caching or paging. A learner who expects "fetch, store in SwiftData, show with @Query" is left confused. Official Apple tutorials are where many developers learn what good practice looks like. An article called "Dissecting an app's architecture" should either show a sound architecture, or clearly label the shortcuts as shortcuts. Right now it does neither. My questions: Is ArticleStore intended as a pattern to follow, or only a placeholder? What would Apple recommend for this app's data layer with a real async network service, including caching and paging?
0
0
163
1w
.bottomBar toolbar item missing after rotation in NavigationSplitView on iOS 26 (Regular width / compact height)
A ToolbarItem(placement: .bottomBar) inside a NavigationSplitView detail/destination view is missing after a device rotation on iOS 26. The bottom toolbar is missing until the view has been presented in both orientations, after which it renders correctly from then on. The issue does not reproduce on iOS 18. Environment iOS 26 only — does not reproduce on iOS 18 iPhone 17 Pro Max and iPhone 17 Air (i.e. devices that expose the landscape size class Regular width / compact height) SwiftUI NavigationSplitView with .balanced style Steps to reproduce Run the sample below on an iPhone 17 Pro Max or Air (or a simulator of either). Open the detail view (which contains a .bottomBar toolbar item) while the device is in either orientation. Rotate the device. Observe that the bottom toolbar is now missing. Expected behavior The .bottomBar button remains visible across rotation, regardless of which orientation the view was first presented in. Actual behavior On first presentation, rotating the device causes the bottom toolbar to disappear. Once the view has been presented in both landscape and portrait (roughly the third presentation), the bottom bar renders correctly and continues to behave correctly afterward. The behavior is inconsistent import SwiftUI @main struct MinimumReproducibleEventApp: App { var body: some Scene { WindowGroup { NavigationSplitView(columnVisibility: .constant(.all)) { NavigationLink("Primary") { ContentView() } } detail: { Text("Hello") } .navigationSplitViewStyle(.balanced) } } } ContentView import SwiftUI struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .toolbar { ToolbarItem(placement: .bottomBar) { Button("Hello") { print("hello") } } } } }
Topic: UI Frameworks SubTopic: SwiftUI
7
2
595
1w
PhotosPicker selection badges initially appear blue, then change to the correct tint after backgrounding
Hello Apple Developer Team, I’m developing an iOS camera app called 1/250 using SwiftUI and the system photo picker (PhotosPicker). I’ve encountered an issue where the photo picker’s selection badge colors are inconsistent between the initial presentation and returning from the background. Steps to Reproduce 1. Open the app and present PhotosPicker. 2. Select multiple photos. 3. The numbered selection badges (1, 2, 3, etc.) appear in the default system blue, despite the app using yellow as its accent color. 4. Send the app to the background without dismissing PhotosPicker. 5. Return to the app. 6. The same selection badges now appear in the correct yellow color. Expected Behavior The numbered selection badges should use the app’s yellow tint color consistently, including when PhotosPicker is first presented. Actual Behavior * Initial presentation: Blue selection badges. * After backgrounding and returning: Yellow selection badges. * No changes to the selected photos or app settings are required. Questions 1. Is this a known issue with SwiftUI PhotosPicker or its underlying UIKit implementation? 2. Why would the tint color be applied correctly only after the app returns from the background? 3. Is there a recommended way to ensure the correct tint is applied before the picker is first displayed? 4. Is there an Apple-supported workaround that avoids recreating or replacing the system photo picker? I would prefer to continue using Apple’s native PhotosPicker rather than implementing a custom photo selection interface. Any guidance from Apple engineers would be greatly appreciated. Thank you!
Topic: UI Frameworks SubTopic: SwiftUI
0
0
140
1w
Button or onTapGesture grows its hit region by a fixed amount past the view’s bounds.
SwiftUI Button hit area extends ~16pt beyond its visual frame — expected OS behavior? Hi everyone, I’m working on a custom SwiftUI segmented control and noticed some unexpected hit-testing behavior with Button. I have a button structured roughly like this: Button { selectItem(at: index) } label: { ZStack { if selectedIndex == index { selectedBackground } SegmentCellView( tab: tab, isSelected: selectedIndex == index ) } .frame(maxWidth: .infinity) .contentShape(Rectangle()) } .accessibilityLabel(Text(tab.labelText)) The visual frame of the button has a certain height, but when testing on a real device, I can tap approximately 16pt outside the button's visible frame and the button still receives the tap. This seems to happen even though I explicitly use: .contentShape(Rectangle()) to define the tappable shape. My questions are: Is this ~16pt expansion of the interactive area expected SwiftUI/OS behavior? Is this related to Apple's minimum hit-target/accessibility guidelines being automatically applied to controls such as Button? If so, is there an official API/documentation describing this behavior? Is there a recommended way to make the Button's hit-testing area exactly match the bounds defined by .contentShape(Rectangle()), if that is actually possible? I'm particularly interested in understanding whether this is intentional system behavior or something caused by the ButtonStyle / layout hierarchy. Thanks!
2
1
150
1w
CPU spike when using RealityView in iOS
CPU spikes to over 100% and stays in that range when realityView (even without content) is added to an iOS view in SwiftUI. On device, it takes approximately 20 seconds before you see this behavior. How are developers getting around this in iOS apps? Is it getting past app review? Xcode 27.2, iOS27.2.1
0
0
81
1w
Can a complication/widget render a continuously animated custom graphic (watchOS)?
Can a complication/widget render a continuously animated custom graphic (watchOS)? I design abstract, number-free clock faces (see rhei.watch for examples — canvas-based, continuously animated) and I’m exploring whether something similar could work on Apple Watch. Since watchOS doesn’t allow fully custom third-party watch faces, I’m trying to understand what’s actually possible within the current constraints: Can a complication or widget render a continuously animated, custom canvas-style graphic — not just static icons/text/SF Symbols — similar to what’s possible with iOS lock screen widgets? Is there any path today for a third-party app to offer a watch-face-like experience, even without literally replacing the system face (e.g. via Smart Stack, a full-screen complication, Live Activities on watchOS, or something else I’m not aware of)? Any pointers to the right documentation, sample code, or past discussions would be really helpful before I invest time in building this. Thanks! Thomas
0
0
68
1w
Mac Catalyst: disabled SwiftUI toolbar buttons turn into pills and don’t update their state
Hi everyone, we’ve been fighting with disabled toolbar buttons in our Mac Catalyst app and wanted to check whether others are seeing the same thing, or whether we’re missing something. Our toolbar lives in a SwiftUI NavigationStack, so Catalyst bridges it into the window’s NSToolbar. Enabled buttons look and work great: native buttons with a round 36 × 36 pt glass. But as soon as a button uses .disabled(_:), things fall apart: It turns into a wider pill. A button that is disabled when it appears becomes an image item instead of a button (NSToolbarImageView with a UIImage), and its glass grows to 47 × 36 pt. Its state doesn’t update. Toggling .disabled(_:) doesn’t reach the existing toolbar item. It only changes if we give the ToolbarItem a new id, which then brings back the pill. Disabling the NSToolbarItem ourselves doesn’t stick. UIKit revalidates the toolbar whenever any item changes, and copies the bar button’s enabled state back over ours. Drawing our own image to fix the shape crashed AppKit (“Unable to install constraint on view”) as soon as the item switched back to enabled. For now we keep the SwiftUI button enabled on the Mac and disable the native NSToolbarItem ourselves. We find the toolbar via NSToolbar.willAddItemNotification and use KVO to put the state back whenever UIKit overrides it. It works, but it feels like it shouldn’t be necessary. Here’s a minimal example: struct ContentView: View { @State private var canUndo = false var body: some View { NavigationStack { Button("Toggle") { canUndo.toggle() } .toolbar { ToolbarItem(placement: .topBarLeading) { Button("Undo", systemImage: "arrow.uturn.backward") {} .labelStyle(.iconOnly) .disabled(!canUndo) } } } } }Seen on macOS 27.2 and 26.7.1, Xcode 27.2. Filed as FB25597608. Is there a supported way to get a disabled toolbar button that stays a normal native button? Any hints are very welcome. Thanks!
Replies
0
Boosts
0
Views
52
Activity
2d
SwiftUI TabView with a .prominent tab exhibits unexpected rendering behavior during iPhone Duo display transitions
Hi Apple Support Team, I would like to report an iPhone Duo-specific regression that appears in iOS 27.2.1. The same application behaves correctly on iOS 27.1, and I have been able to reproduce the issue consistently using a minimal sample application. When running the application on iPhone Duo, transitioning from the outer display to the inner display while the device is opened in landscape orientation results in unexpected UI rendering. Specifically, a large arc-shaped visual element associated with a tab configured with the .prominent role appears on screen after the transition. In addition to the rendering issue, we have observed unexpected UI presentation behavior during these display transitions when a tab is assigned the .prominent role. The issue appears to be tied to the .prominent tab role. When all tabs use the default role, the application behaves as expected and neither the rendering issue nor the unexpected UI behavior is observed. A sample application reproducing the issue is attached. Steps to Reproduce Launch the attached sample application on iPhone Duo running iOS 27.2.1. Ensure that one of the tabs is configured with the .prominent role. Start on the outer display. Open the device and transition to the inner display in landscape orientation. Observe the UI during and after the transition. Expected Result TabView should transition cleanly between the outer and inner displays without rendering artifacts or unexpected UI behavior. Actual Result A large arc-shaped visual artifact appears on screen. Unexpected view presentation behavior may occur during the display transition. Multiple animation- and transform-related warnings are logged. // Attached run time logs. Additional Notes Reproducible in both our production application and the attached sample application. The issue appears to be tied to SwiftUI TabView when a tab is assigned the .prominent role. The issue was not observed on iOS 27.1. The issue occurs during transitions between the outer and inner displays on iPhone Duo. Removing the .prominent role eliminates the issue. Could you please let us know whether this is a known issue with SwiftUI TabView and .prominent tabs during iPhone Duo display transitions on iOS 27.2.1? If there is an existing Feedback report, Apple Developer Forums discussion, internal tracking issue, or recommended workaround, we would greatly appreciate any guidance. Screenshots and a sample project are attached. Thank you for your time and assistance. Please let me know if any additional diagnostics, sysdiagnose captures, logs, or sample projects would be helpful. Best regards, Manish
Replies
1
Boosts
0
Views
194
Activity
2d
Regression: AxisValueLabel multiLabelAlignment parameter ignored in iOS 27
Hello Apple SwiftUI / Swift Charts Engineering Team, I am writing to report a layout regression regarding Swift Charts in iOS 27. The multiLabelAlignment property on AxisValueLabel has stopped working as expected, whereas it functions perfectly in iOS 26. Bug Description: When configuring custom string values within AxisMarks using AxisValueLabel with multiLabelAlignment: .trailing, the alignment configuration is completely ignored on iOS 27. Labels fail to align text properly to the trailing edge, causing rendering layout issues for multi-line or custom text labels on the Y-axis. This exact same implementation compiles and aligns correctly on iOS 26. Code Snippet to Reproduce: swift struct YAxisAlignmentBugView: View { // data points to render the chart frame let data = [(date: Date(), revenue: 3000.0), (date: Date().addingTimeInterval(10000), revenue: 4000.0)] var body: some View { Chart(data, id: .date) { item in LineMark(x: .value("Date", item.date), y: .value("Revenue", item.revenue)) } .frame(height: 300) .padding() .chartYAxis { AxisMarks(preset: .aligned, position: .trailing, values: [12.0, 600.0, 3000.0, 6000.0]) { value in if let revenue = value.as(Double.self) { // BUG: multiLabelAlignment: .trailing is completely ignored on iOS 27 AxisValueLabel("y-(Int(revenue))", anchor: .leading, multiLabelAlignment: .trailing) } } } } } Steps to Reproduce: Render a Swift Chart containing a .chartYAxis configuration with position: .trailing. Pass a string directly using AxisValueLabel(customText, anchor: .leading, multiLabelAlignment: .trailing). Run the application on an iOS 26 simulator (text aligns properly to the trailing edge). Run the identical application code on an iOS 27 simulator. Expected Behavior: The text inside the AxisValueLabel should honor the multiLabelAlignment: .trailing parameter and align the text strings flush right. Actual Behavior: The multiLabelAlignment layout modifier is ignored on iOS 27, resulting in unexpected default left-alignment of the text strings. Attachments: I have attached screenshots from the Xcode Simulator demonstrating the regression: Please let me know if you need any further diagnostic details. Best regards, Soumyajit Das
Replies
3
Boosts
0
Views
336
Activity
2d
Regression: AxisValueLabel anchor parameter ignores .topLeading on iOS 27
Hello Apple SwiftUI / Swift Charts Engineering Team, I am writing to report a layout regression regarding Swift Charts in iOS 27. The anchor property on AxisValueLabel has stopped honoring the .topLeading layout coordinate, whereas it functions perfectly in iOS 26. Bug Description: To prevent the first label on a bottom X-axis from clipping past the left screen edge, a .topLeading anchor is applied. In iOS 27, this specific anchor alignment is completely ignored. The chart falls back to a standard top-center alignment, causing the initial boundary label to clip off-screen. Core Code Snippet to Reproduce: struct XAxisAnchorBugView: View { let dates = [ Calendar.current.date(from: DateComponents(year: 2026, month: 10, day: 1))!, Calendar.current.date(from: DateComponents(year: 2026, month: 10, day: 2))! ] var body: some View { Chart(dates, id: .self) { date in LineMark(x: .value("Date", date), y: .value("Value", 100)) } .frame(height: 300) .padding() .chartXAxis { AxisMarks(preset: .aligned, position: .bottom, values: .stride(by: .day, count: 1)) { value in AxisTick() let currentAnchor: UnitPoint = { guard let currentDate = value.as(Date.self) else { return .top } // BUG: .topLeading layout anchor parameter is completely ignored on iOS 27 return (currentDate == dates.first) ? .topLeading : .top }() AxisValueLabel(format: .dateTime.month(.abbreviated).day(), anchor: currentAnchor) } } } } Steps to Reproduce: Render an X-axis with a .bottom position. Assign anchor: .topLeading strictly to the first axis element's label. Run on an iOS 26 simulator (the first label anchors its top-left corner correctly, preventing edge clipping). Run on an iOS 27 simulator (the .topLeading anchor is ignored, reverting to standard top-center alignment). Expected Behavior: AxisValueLabel should position its layout bounding box using the .topLeading anchor point when specified. Actual Behavior: The layout engine ignores the .topLeading parameter on iOS 27, causing the boundary text to shift left and clip. Attachments: I have attached Xcode Simulator screenshots demonstrating this regression: Best regards, Soumyajit Das
Replies
3
Boosts
0
Views
361
Activity
2d
How to handle all the core AppleEvents
Glancing through the APIs, SwiftUI can handle the open app, reopen app, open doc, and quit core events (with the “aevt” suite ID). What about the print doc and open content events? If there are no hooks (yet), how can I implement them the traditional way without clashing with SwiftUI?
Replies
2
Boosts
0
Views
815
Activity
2d
iPhone Duo Unfolded Safe Areas
Hi, my app is currently built on Xcode 27.1 I am working on upgrading to Xcode 27.2 We have a regression issue whereby, the top safeArea is 82 despite the vertical bar being opted in and active. This only happens on unfolded landscape. Our right safeArea is 0 for the window and is 84 for the view safeArea. Both window and view safeAreas have the top safe area of 82 though. We would like to know what could be the cause behind the top safeArea being activated. Note: this is not an issue for iOS 27.1
Replies
2
Boosts
0
Views
206
Activity
3d
SwiftUI Architecture Guide
Application Types Applications are divided into Document-based and Library-based. A document-based application stores user data in individual, standalone files. Users manually name and organize those files in a local system or synced cloud storage such as iCloud. The software typically opens multiple windows for different projects. This framing is for standalone, complex files that need to be shared, exported, or handled independently. A library-based application manages data in one unified, central repository, locally or through remote cloud databases. Spotify, Netflix, and Notion are the examples shown. The file system is hidden; updates are saved automatically in real time; and a single window supports browsing, search, and access to the synchronized data collection from any device. Model Types Four model types: Data, Domain, Application, and Presentation. Apple Platforms In Apple MVC (AppKit / UIKit), the model branches to Data, Domain, and Presentation. In SwiftUI, Model branches to Data and Domain. Project Structure SwiftUI App Folders Swift Package Folders App Modularization Not every module in a large application needs to be extracted into a separate framework or Swift Package. Logical modularization can also be achieved through a well-organized folder structure within the main project. Introduce separate packages or frameworks only when there is a clear benefit, such as independent reuse, distribution, build isolation or ownership. Avoid unnecessary project and dependency management overhead. State Management & Data Flow Source of truth is “a key concept in SwiftUI”: a single place to store a piece of data, with everywhere else reading the same piece of data. Environment is SwiftUI’s native dependency-injection mechanism. It allows shared dependencies, domain models, and services to be injected at the appropriate view-hierarchy level and accessed where needed without explicit parameter passing or unnecessary coupling. It is described as a tool for managing dependencies and sharing state across the view hierarchy. Domain Model Ownership Domain Models should be owned by the highest relevant SwiftUI view in the hierarchy that defines their context and lifecycle. NavigationStack owns the Domain Models for its navigation context and makes them available to descendant views through @Environment. When a NavigationStack is embedded in a TabView or NavigationSplitView, ownership moves up to the TabView or NavigationSplitView so the models can be shared across tabs or split views. The stated result is clear ownership scope, sharing where needed, and isolation between independent navigation contexts. Previews & UI Testing Environment injection makes SwiftUI Previews and UI Tests easier to configure by allowing real Domain Models to be replaced with mock or dummy instances. Views can be tested independently with controlled data and predictable states, without requiring real services, network requests, or application setup. Domain and Data Model Examples For a library-based app with remote data. Additional Domain Model Examples E-commerce Catalog, ShoppingCart, OrderHistory, Wishlist Banking MyAccounts, MyCards, MyTransactions, MyInvestments Social Network Feed, Conversations, Notifications, Friends Healthcare MyAppointments, MedicalHistory, Prescriptions, MyHealth Education Courses, MyCourses, Assignments, MyGrades, LearningProgress Real Estate PropertyCatalog, MyProperties, Favorites, Appointments Hotel Booking Destinations, Search, MyBookings, TravelHistory Food Delivery RestaurantCatalog, ShoppingCart, MyOrders, DeliveryTracking Project Management Projects, MyTasks, TeamMembers, Notifications Insurance MyPolicies, MyClaims, Coverage, Documents Smart Home MyHomes, Devices, Automations, EnergyUsage Fitness MyPlans, MyProgress, MyGoals, WorkoutHistory Other Search, Dashboard, Favorites, Notifications, Settings, ActivityHistory, Recommendations, Subscription, DocumentLibrary ViewModel? - MVVM In SwiftUI, the View encapsulates the UI content (body), its state (properties), and its actions or tasks (functions). This is possible because SwiftUI is designed around a declarative, state-driven UI model. In Android and .NET platforms, a separate ViewModel is typically required to hold and manage the View's state. Projects that intoduce ViewModels in SwiftUI add unnecessary architectural complexity, boilerplate, and code duplication; synchronization issues; unclear state ownership; additional lifecycle management; more abstractions; harder debugging; and increased maintenance, without meaningful benefits over SwiftUI's native state management. In UIKit, introducing a separate ViewModel layer is often unnecessary, as UIViewController already serves as the presentation model, handling presentation logic and coordinating the view. Non-UI responsibilities can be delegated to dedicated ModelControllers or Managers, avoiding unnecessary layers and abstractions. Domain Models vs. ViewModels Domain Models are view-independent, while ViewModels are view-dependent. A ViewModel is tightly coupled to the structure, state, and lifecycle of a specific View. Whenever the View code changes, its ViewModel often requires corresponding coding changes, and vice versa, creating additional maintenance and synchronization overhead. Domain Models, on the other hand, represent application context and business functionality independently of the UI. This separation preserves UI independence and allows the same Domain Models to be shared across different screens and platforms, such as iPhone, iPhone Duo, iPad, and macOS, without duplicating or adapting business logic for each View. This makes Domain Models a more scalable and maintainable approach for modern SwiftUI applications, particularly those targeting multiple screen sizes and platforms.
Replies
1
Boosts
0
Views
266
Activity
3d
SwiftUI custom focusable view cannot acquire focus programmatically on iPad with a hardware keyboard connected
On iPad, a SwiftUI view using .focusable(interactions: .edit) and .focused($isFocused) cannot acquire focus when a hardware keyboard is already connected. Setting isFocused = true from a button leaves it false. Tapping the view also leaves it unfocused, although the tap is received. Pressing Tab can focus the same view. struct FocusProbeView: View { @FocusState private var isFocused: Bool var body: some View { VStack { Text("Target") .focusable(interactions: .edit) .focused($isFocused) .onTapGesture { print("Target tapped") } Text("isFocused = \(isFocused)") Button("Focus target") { isFocused = true } } .defaultFocus($isFocused, true) } }Steps to reproduce: Run this view on an iPad with a hardware keyboard connected. Tap “Focus target”, then tap “Target”. Observe that isFocused remains false. Press Tab. The target can receive focus through keyboard navigation. Disconnect the keyboard. Restart the app and tap “Focus target” again. isFocused becomes true. Reconnecting the keyboard does not remove that focus. Expected: A visible custom view marked .focusable(interactions: .edit) can receive focus through @FocusState, including when a hardware keyboard is connected. Actual: Programmatic focus fails when the keyboard is already connected. A native TextField tested with the same button and @FocusState does receive focus. Environment: iPad model: MU1V2NF/A; iPadOS version: 26.7.2; Xcode version: 27.2; hardware keyboard: Logi Folio Touch. iPad model: Device Hub iPad Pro 11-inch (M5); iPadOS version: 27.2; Xcode version: 27.2; hardware keyboard: Device Hub.
Replies
1
Boosts
0
Views
230
Activity
3d
Inversed swipe gesture in VStack/LazyVStack vs List
I'm using a row swipe to delete gesture in a LazyVStack just the same way I would do in a List and I have to inverse the gesture (from left to right) to allow the Delete button appearing whereas in a List, the left to right swipe gesture works as expected. The following code reveals that unexpected/anti natural behavior. iOS works as expected for the same code. import SwiftUI import Playgrounds struct ContentView: View { var body: some View { VStack { // anti-natural and inconsistent gesture // LazyVStack { // anti-natural and inconsistent gesture // List { // natural gesture HStack { Text("Swipe Test") Spacer() } .padding(10) .frame(height: 40) .background { Color.blue } .swipeActions(edge: .trailing, allowsFullSwipe: false) { Button("Delete", role: .destructive) {} } } } }Setup: Macbook Pro M1 Max / macOS 27.2.1 / Xcode 27.2
Replies
0
Boosts
0
Views
36
Activity
3d
Supported way to hide the system time in a full-screen watchOS clock app?
I'm building a standalone watchOS app (SwiftUI, watch-only) whose main screen is its own full-screen clock. The system time in the top-right corner duplicates our clock, so we'd like to hide it while this view is visible. I'd like to know which API is supported for this in an App Store app. What I tried (watchOS 27.2 SDK, Xcode 27.2): .persistentSystemOverlays(.hidden) on the root view and on the scene. The system time stays visible. In a variant with a NavigationStack and a hidden navigation bar, the time was briefly absent after launch, but it came back within about 20 seconds. .statusBarHidden(_:) and .toolbarVisibility(.hidden, for: .statusBar) are marked unavailable on watchOS in the SDK. View._statusBarHidden(_:) hides the system time reliably. In the watchOS SwiftUI interface it is public, available on watchOS since 6.0, and has no @_spi. It inlines to _statusBar(hidden:). However, it's underscored and I can't find documentation for it. Minimal example: struct ClockView: View { var body: some View { MyFullScreenClock() .persistentSystemOverlays(.hidden) // documented, but time remains visible ._statusBarHidden(true) // hides the time, but undocumented } }I've noticed this modifier in shipping open-source watchOS code, for example Home Assistant's watch app (Sources/WatchApp/Home/WatchHomeView.swift). That doesn't tell me whether Apple supports it, though. Questions: Is _statusBarHidden(_:) / _statusBar(hidden:) a supported API for a distributed watchOS app? If not, is there a documented way for a full-screen clock app to hide the system time, or is the system time intentionally always shown in third-party apps? I can share a small sample project that toggles between the documented overlay preference and the underscored modifier. Thanks!
Replies
2
Boosts
0
Views
89
Activity
3d
iPhone Duo: Keep app on inner display while hinge is open (like Clock)?
I'm building a night-light app for iPhone Duo. When the device is partly open in tent mode, the lamp starts on the inner display. As soon as I set the phone down on a table, the system moves my window to the outer display, even though the hinge stays open. Apple's Clock app stays on the inner display in the same pose, so it seems possible at the system level. Steps Open iPhone Duo to ~80° (tent). Launch the app on the inner display. Set the device down on a table. Observed (logged from the app) UIHinge.status stays .partiallyOpen (~80°), not .closed. UIDevice.orientation goes portraitUpsideDown → faceDown → landscapeRight. UIScreen.didDisconnectNotification fires and UIScreen.screens drops the inner screen. The window moves to the outer screen (466×678). What I've tried Restricting UISupportedInterfaceOrientations to portrait only Turning on Rotation Lock Reading UIHingeInteraction (read-only, no effect on display routing) Looking at UISceneAccessory.cameraCapture, which only applies with an active capture session and a fully open device Question Is there a supported way for a scene to prefer or stay on the inner display while the hinge isn't closed? If not, I'll file a Feedback Assistant request. iPhone Duo · iOS 27.2 · Xcode 27.2
Topic: UI Frameworks SubTopic: SwiftUI
Replies
2
Boosts
0
Views
89
Activity
5d
NavigationSplitView sidebar expansion temporarily oversizes split view and collapses toolbar search
[Submitted as FB25597038] Showing the sidebar in a two-column NavigationSplitView briefly collapses the toolbar search field, even though the window doesn't resize. Search is right-aligned on the detail container using .searchable, ToolbarSpacer(.flexible), and DefaultToolbarItem(kind: .search). The sample below uses static content and the native sidebar toggle and animation. Setting only the sidebar item's collapseBehavior to .useConstraints avoids the issue. It occurred in both recorded baseline expansions and neither expansion with the workaround. Environment macOS 27.2.1 (26B131) Xcode 27.2 (27B52) macOS SDK 27.2 (26B118) Native macOS app, arm64, deployment target macOS 27.0 Initial window: 906 × 600 points Sidebar minimum/ideal/maximum widths: 180/240/360 points Repro Create a new macOS App project named SidebarAnimationRepro, using SwiftUI and Swift. Set the deployment target to macOS 27.0. Replace SidebarAnimationReproApp.swift and ContentView.swift with the code below. Leave usesWorkaround set to false. Build and run. Keep the initial 906-point window width. Click Hide Sidebar and let the transition settle. Click Show Sidebar and watch the search field during expansion. Stop the app, change usesWorkaround to true, and run again. Repeat steps 4–5 to compare the behavior. Expected The split view should stay within the window during sidebar expansion. The search field should stay visible at its normal width without briefly collapsing or disappearing. Actual The split view temporarily grows to 1,146 points while the window stays 906 points wide. Search shrinks from 325 to 36 points and disappears, then returns to its normal size and visibility. The toolbar, search item, and search field remain the same instances, and toolbar item order doesn't change. In one capture, search collapsed about 123 ms after expansion started, returned at 274 ms, and the split view settled at 283 ms. With .useConstraints, the split view stayed at 906 points and search stayed visible at 325 points throughout both hide/show cycles. Screenshots Three frames before, during, and after the sidebar expansion: Sample Code SidebarAnimationReproApp.swift import SwiftUI @main struct SidebarAnimationReproApp: App { var body: some Scene { WindowGroup("Sidebar Animation Repro") { ContentView() } .defaultSize(width: 906, height: 600) } }ContentView.swift import AppKit import SwiftUI struct ContentView: View { @State private var searchText = "" var body: some View { NavigationSplitView { List { Label("Example", systemImage: "folder") } .navigationSplitViewColumnWidth(min: 180, ideal: 240, max: 360) } detail: { Text("Synthetic detail content") .frame(minWidth: 0, maxWidth: .infinity, maxHeight: .infinity) .background { SplitViewAttachment() } .searchable(text: $searchText, placement: .toolbar) .toolbar { ToolbarSpacer(.flexible) DefaultToolbarItem(kind: .search) } } .toolbar(removing: .title) .frame(minWidth: 720, minHeight: 420) } } struct SplitViewAttachment: NSViewRepresentable { func makeNSView(context: Context) -> Attachment { Attachment() } func updateNSView(_ view: Attachment, context: Context) { view.applyWorkaround() } final class Attachment: NSView { private let usesWorkaround = false override func hitTest(_ point: NSPoint) -> NSView? { nil } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() applyWorkaround() } /// The split controller can enter the responder chain after the view enters its window. override func layout() { super.layout() applyWorkaround() } fileprivate func applyWorkaround() { guard usesWorkaround, window != nil else { return } let responders = sequence(first: self as NSResponder, next: \.nextResponder) guard let controller = responders.first(where: { $0 is NSSplitViewController }) as? NSSplitViewController, let sidebar = controller.splitViewItems.first(where: { $0.behavior == .sidebar }), sidebar.collapseBehavior != .useConstraints else { return } sidebar.collapseBehavior = .useConstraints } } }
Replies
0
Boosts
0
Views
49
Activity
5d
@FocusedValue from .focusedSceneValue from the Scene Commands
Hi, In iPadOS can we use a .focusedSceneValue, defined from a command/Button inside a Scene, from inside the .command modifier attached to the scene? Like this: @main struct test_focusedSceneValueApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }         .commands {             NavigationCommands()         }     } } struct NavigationCommands: Commands {     @FocusedValue(\.filterAction) var filterAction     var body: some Commands {         CommandMenu("Navigate") {             Button("Test focusedSceneValue") {                 filterAction?()             }             .keyboardShortcut("5")         }     } } struct ContentView: View {     @FocusState var isFiltering: Bool     @State private var focusField: String = "teste field teste"     var body: some View {         TextField("teste focus", text: $focusField)             .focused($isFiltering)             .focusedSceneValue(\.filterAction) {                 print("test successful")                 isFiltering = true             }     } This code is almost the same from the sample code from the documentation, however I can only retrieved nil values from the @FocusedValue and not the defined value. Thanks.
Replies
5
Boosts
0
Views
2.2k
Activity
1w
Article Accelerator tutorial: “Dissecting an app’s architecture” doesn’t explain data flow, and ArticleStore isn’t a realistic network simulation
Here's a sharper version. It's blunt about how badly the app is built, but it avoids swearing and insults, because forum moderators remove posts like that. Title: Article Accelerator: an architecture tutorial built on patterns we shouldn't copy Text: The tutorial "Dissecting an app's architecture" promises to show how data flows in and through Article Accelerator: https://developer.apple.com/tutorials/app-dev-training/dissecting-an-apps-architecture For a tutorial whose whole subject is architecture, the sample app is a poor example of it. The article never actually traces the data flow, and the code it describes uses patterns that most SwiftUI guidance tells you to avoid. The "simulated network service" isn't one. The tutorial says ArticleStore simulates a network service. In reality it's a singleton that synchronously loads JSON files from the bundle. It can't be slow, can't fail and can't return partial data, so it simulates none of what makes networking hard. It cannot be turned into an async URLSession call without throwing it away and redesigning the data layer. Views fetch data directly from a singleton. DetailView does private let articles = ArticleStore.shared.articles() as a stored property. There's no @Observable model, no loading state, no error state, and no dependency injection. This makes the views impossible to test with fake data and hides the data flow the tutorial claims to explain. Error handling is print and fatalError. A broken article file is silently skipped with print. An unreadable folder crashes the app. Failing to delete user data also crashes the app. SwiftData setup is inconsistent. The app creates one ModelContainer, then ArticleStateManager creates a separate ModelContext instead of using the container's mainContext. So writes through the manager and @Query reads go through different contexts. On top of that, the environment default for articleStateManager quietly creates a second ModelContainer with try!, so any window that forgets to inject it gets a different container. The structure isn't structured. The tutorial's challenge asks you to sort the Models folder into three categories, but the project puts everything in one flat folder, including ArticleStateManager, which isn't a model at all. Article, the main model, isn't even in it. The key design decision is never explained. Articles live only in memory while user data lives in SwiftData, and views join them by ID. That's a reasonable split, but the tutorial never says so, never explains why, and never addresses what it means for offline support, caching or paging. A learner who expects "fetch, store in SwiftData, show with @Query" is left confused. Official Apple tutorials are where many developers learn what good practice looks like. An article called "Dissecting an app's architecture" should either show a sound architecture, or clearly label the shortcuts as shortcuts. Right now it does neither. My questions: Is ArticleStore intended as a pattern to follow, or only a placeholder? What would Apple recommend for this app's data layer with a real async network service, including caching and paging?
Replies
0
Boosts
0
Views
163
Activity
1w
.bottomBar toolbar item missing after rotation in NavigationSplitView on iOS 26 (Regular width / compact height)
A ToolbarItem(placement: .bottomBar) inside a NavigationSplitView detail/destination view is missing after a device rotation on iOS 26. The bottom toolbar is missing until the view has been presented in both orientations, after which it renders correctly from then on. The issue does not reproduce on iOS 18. Environment iOS 26 only — does not reproduce on iOS 18 iPhone 17 Pro Max and iPhone 17 Air (i.e. devices that expose the landscape size class Regular width / compact height) SwiftUI NavigationSplitView with .balanced style Steps to reproduce Run the sample below on an iPhone 17 Pro Max or Air (or a simulator of either). Open the detail view (which contains a .bottomBar toolbar item) while the device is in either orientation. Rotate the device. Observe that the bottom toolbar is now missing. Expected behavior The .bottomBar button remains visible across rotation, regardless of which orientation the view was first presented in. Actual behavior On first presentation, rotating the device causes the bottom toolbar to disappear. Once the view has been presented in both landscape and portrait (roughly the third presentation), the bottom bar renders correctly and continues to behave correctly afterward. The behavior is inconsistent import SwiftUI @main struct MinimumReproducibleEventApp: App { var body: some Scene { WindowGroup { NavigationSplitView(columnVisibility: .constant(.all)) { NavigationLink("Primary") { ContentView() } } detail: { Text("Hello") } .navigationSplitViewStyle(.balanced) } } } ContentView import SwiftUI struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .toolbar { ToolbarItem(placement: .bottomBar) { Button("Hello") { print("hello") } } } } }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
7
Boosts
2
Views
595
Activity
1w
PhotosPicker selection badges initially appear blue, then change to the correct tint after backgrounding
Hello Apple Developer Team, I’m developing an iOS camera app called 1/250 using SwiftUI and the system photo picker (PhotosPicker). I’ve encountered an issue where the photo picker’s selection badge colors are inconsistent between the initial presentation and returning from the background. Steps to Reproduce 1. Open the app and present PhotosPicker. 2. Select multiple photos. 3. The numbered selection badges (1, 2, 3, etc.) appear in the default system blue, despite the app using yellow as its accent color. 4. Send the app to the background without dismissing PhotosPicker. 5. Return to the app. 6. The same selection badges now appear in the correct yellow color. Expected Behavior The numbered selection badges should use the app’s yellow tint color consistently, including when PhotosPicker is first presented. Actual Behavior * Initial presentation: Blue selection badges. * After backgrounding and returning: Yellow selection badges. * No changes to the selected photos or app settings are required. Questions 1. Is this a known issue with SwiftUI PhotosPicker or its underlying UIKit implementation? 2. Why would the tint color be applied correctly only after the app returns from the background? 3. Is there a recommended way to ensure the correct tint is applied before the picker is first displayed? 4. Is there an Apple-supported workaround that avoids recreating or replacing the system photo picker? I would prefer to continue using Apple’s native PhotosPicker rather than implementing a custom photo selection interface. Any guidance from Apple engineers would be greatly appreciated. Thank you!
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
140
Activity
1w
Button or onTapGesture grows its hit region by a fixed amount past the view’s bounds.
SwiftUI Button hit area extends ~16pt beyond its visual frame — expected OS behavior? Hi everyone, I’m working on a custom SwiftUI segmented control and noticed some unexpected hit-testing behavior with Button. I have a button structured roughly like this: Button { selectItem(at: index) } label: { ZStack { if selectedIndex == index { selectedBackground } SegmentCellView( tab: tab, isSelected: selectedIndex == index ) } .frame(maxWidth: .infinity) .contentShape(Rectangle()) } .accessibilityLabel(Text(tab.labelText)) The visual frame of the button has a certain height, but when testing on a real device, I can tap approximately 16pt outside the button's visible frame and the button still receives the tap. This seems to happen even though I explicitly use: .contentShape(Rectangle()) to define the tappable shape. My questions are: Is this ~16pt expansion of the interactive area expected SwiftUI/OS behavior? Is this related to Apple's minimum hit-target/accessibility guidelines being automatically applied to controls such as Button? If so, is there an official API/documentation describing this behavior? Is there a recommended way to make the Button's hit-testing area exactly match the bounds defined by .contentShape(Rectangle()), if that is actually possible? I'm particularly interested in understanding whether this is intentional system behavior or something caused by the ButtonStyle / layout hierarchy. Thanks!
Replies
2
Boosts
1
Views
150
Activity
1w
CPU spike when using RealityView in iOS
CPU spikes to over 100% and stays in that range when realityView (even without content) is added to an iOS view in SwiftUI. On device, it takes approximately 20 seconds before you see this behavior. How are developers getting around this in iOS apps? Is it getting past app review? Xcode 27.2, iOS27.2.1
Replies
0
Boosts
0
Views
81
Activity
1w
Can a complication/widget render a continuously animated custom graphic (watchOS)?
Can a complication/widget render a continuously animated custom graphic (watchOS)? I design abstract, number-free clock faces (see rhei.watch for examples — canvas-based, continuously animated) and I’m exploring whether something similar could work on Apple Watch. Since watchOS doesn’t allow fully custom third-party watch faces, I’m trying to understand what’s actually possible within the current constraints: Can a complication or widget render a continuously animated, custom canvas-style graphic — not just static icons/text/SF Symbols — similar to what’s possible with iOS lock screen widgets? Is there any path today for a third-party app to offer a watch-face-like experience, even without literally replacing the system face (e.g. via Smart Stack, a full-screen complication, Live Activities on watchOS, or something else I’m not aware of)? Any pointers to the right documentation, sample code, or past discussions would be really helpful before I invest time in building this. Thanks! Thomas
Replies
0
Boosts
0
Views
68
Activity
1w