Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

Sorting of FetchResults in TableView broken in xcode 26
Previously, I sorted my FetchResult in a TableView like this: @FetchRequest( sortDescriptors: [SortDescriptor(\.rechnungsDatum, order: .forward)], predicate: NSPredicate(format: "betragEingang == nil OR betragEingang == 0") ) private var verguetungsantraege: FetchedResults<VerguetungsAntraege> ... body ... Table(of:VerguetungsAntraege.self, sortOrder: $verguetungsantraege.sortDescriptors) { TableColumn("date", value:\.rechnungsDatum) { item in Text(Formatters.dateFormatter.string(from: item.rechnungsDatum ?? Date()) ) } .width(120) TableColumn("rechNrKurz", value:\.rechnungsNummer) { item in Text(item.rechnungsNummer ?? "") } .width(120) TableColumn("betrag", value:\.totalSum ) { Text(Formatters.currencyFormatter.string(from: $0.totalSum as NSNumber) ?? "kein Wert") } .width(120) TableColumn("klient") { Text(db.getKlientNameByUUID(id: $0.klient ?? UUID(), moc: moc)) } } rows: { ForEach(Array(verguetungsantraege)) { antrag in TableRow(antrag) } } There seem to be changes here in Xcode 26. In any case, I always get the error message in each line with TableColumn("title", value: \.sortingField) Ambiguous use of 'init(_:value:content:)' Does anyone have any idea what's changed? Unfortunately, the documentation doesn't provide any information.
0
0
175
Jun ’25
NavigationPath.append but .navigationDestination Not Being Called
I am trying to do a bit of fancy navigation in SwiftUI using NavigationPath and am having a problem. I have a root view with includes a button: struct ClassListScreen: View { @Bindable private var router = AppRouter.shared @State private var addCourse: Bool = false ... var body: some View { ... Button("Add Class") { router.currentPath.append(addCourse) }.buttonStyle(.borderedProminent) ... .navigationDestination(for: Bool.self){ _ in ClassAddDialog { course in sortCourses() } } } } router.currentPath is the NavigationPath associated with the operative NavigationStack. (This app has a TabView and each Tab has its own NavigationStack and NavigationPath). Tapping the button correctly opens the ClassAddDialog. In ClassAddDialog is another button: struct ClassAddDialog: View { @Bindable private var router = AppRouter.shared @State private var idString: String = "" ... var body: some View { ... Button("Save") { let course = ... ... (save logic) idString = course.id.uuidString var path = router.currentPath path.removeLast() path.append(idString) router.currentPath = path }.buttonStyle(.borderedProminent) ... .navigationDestination(for: String.self) { str in if let id = UUID(uuidString: str), let course = Course.findByID(id, with: context) { ClassDetailScreen(course: course) } } } } My intent here is that tapping the Save button in ClassAddDialog would pop that view and move directly to the ClassDetailScreen (without returning to the root ClassListScreen). The problem is that the code inside the navigationDestination is NEVER hit. (I.e., a breakpoint on the if let ... statement) never fires. I just end up on a (nearly) blank view with a warning triangle icon in its center. (And yes, the back button takes me to the root, so the ClassAddDialog WAS removed as expected.) And I don't understand why. Can anyone share any insight here?
0
1
105
Oct ’25
unable to click when ZoomNavigationTransition finished
I am using ".navigationTransition(ZoomNavigationTransition.zoom(sourceID: xxx, in: xxx))" to zooms the appearing view from a source view . When the appearing view dismissed, I can only click other view after a delay . It seems that the transition is not finished immediately when the appearing view dismissed . After a delay, the transition finished, than I can click other view. struct ContentView: View { @State private var path: NavigationPath = NavigationPath() @Namespace private var namespace var body: some View { NavigationStack(path: $path) { VStack(spacing: 0) { ForEach(["aaa", "bbb"], id: \.self) { string in Text(string) .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2) .contentShape(Rectangle()) .onTapGesture { path.append(string) } .matchedTransitionSource(id: string, in: namespace) } } .navigationDestination(for: String.self, destination: { route in Text(route) .navigationTransition(ZoomNavigationTransition.zoom(sourceID: route, in: namespace)) }) } } } When using sheet on appearing view, It seems that the transition is finished immediately when the appearing view dismissed. extension String: Identifiable { public var id: String { return self } } struct ContentView: View { @State private var path: NavigationPath = NavigationPath() @Namespace private var namespace @State private var stringToSheet: String? var body: some View { NavigationStack(path: $path) { VStack(spacing: 0) { ForEach(["aaa", "bbb"], id: \.self) { string in Text(string) .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2) .contentShape(Rectangle()) .onTapGesture { stringToSheet = string } .matchedTransitionSource(id: string, in: namespace) } } .sheet(item: $stringToSheet) { newValue in Text(newValue) .navigationTransition(ZoomNavigationTransition.zoom(sourceID: newValue, in: namespace)) } } } }
Topic: UI Frameworks SubTopic: SwiftUI
0
0
75
Jun ’25
When is the StateObject’s autoclosure actually called?
The signature of the StateObject initializer is init(wrappedValue thunk: @autoclosure @escaping () -> ObjectType). The fact that the autoclosure is marked as escaping intrigues me, because that suggests that it could be called after the init has returned. Why this is interesting is because I have some code where the viewmodel given to the @StateObject depends on an implicitly unwrapped optional type, and I expect the top level initialization of the StateObject to crash because the implicitly unwrapped optional is not ready yet, but to my surprise it did not. My theory is that the autoclosure is being called after the View’s initialization had been called, when the dependency is ready. heres a minimal sample of that. class MyDependency: ObservableObject { @Published var value = "Hello" } class MyViewModel: ObservableObject { let dependency: MyDependency init(dependency: MyDependency = TestApp.dependency) { self.dependency = dependency print("✅ ViewModel initialized with dependency:", dependency.value) } } struct ContentView: View { @StateObject private var viewModel = MyViewModel() // ⚠️ expected crash? var body: some View { Text(viewModel.dependency.value).onAppear { TestApp.dependency = Dependency()// dependency is set here after init has been called } } } @main struct TestApp: App { static var dependency: MyDependency! // not ready yet var body: some Scene { WindowGroup { ContentView() } }```
0
0
135
Oct ’25
Document-based app: file picker flickers since macOS 26 update
Description: Since updating to Tahoe, the file picker dialog briefly flickers immediately after opening in my document-based app. This behavior did not occur on macOS Sequoia. Rhe issue does not appear in TextEdit, but it does occur in Paper (a writing app) and Kaleidoscope. Based on this, it seems to affect third-party document-based apps that use standard open panels. Steps to Reproduce: 1. Launch a third-party document-based app. 2. Open the file picker (e.g., via “Open…”). 3. Observe a brief flicker as the dialog appears. Expected Result: The file picker dialog should open smoothly without flickering. Actual Result: The file picker dialog flickers briefly right after appearing. Notes: • Issue introduced in macOS Tahoe. • Not reproducible in macOS Sequoia. Reported through Feedback Assistant: FB20522119
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
0
149
Oct ’25
Unknown error when displaying IntentItems with images in widget configuration intent
Hi everyone, I’m building a simple sticky notes app that allows users to place a note widget on their home screen. Each widget displays a user-created sticky note. To let users choose which note to show, I’ve implemented an Intent that presents a list of existing sticky notes. The list is built using IntentItems, and for each item I assign an image to visually represent the note. Each sticky note can have a different background color and optional image, so I generate a small PNG (150×150, ~30 KB) and include it in the app bundle. However, when I try to display the selection list, I get the following error: The action Select sticky note could not run because an unknown error occurred. If I tap OK and try again, the intent selector appears and works. Here’s what I’d like to understand: What could cause this unknown error when using images in IntentItems? Are there known limitations on image size, source, or format for intent item images? Can I supply a unique image per sticky note, or must all intent items share a common image? Any guidance or insights would be greatly appreciated — I haven’t been able to find clear documentation about image handling in IntentItem for widget configuration. Thanks!
0
0
112
Oct ’25
Symbol not found error when using writingToolsBehavior API built with Xcode 26 and run on iOS 18
When using the writingToolsBehavior API on a TextField and the app compiled with the iOS 26 SDK is run on an iOS 18 device, the app crashes with a symbol not found error. It only crashes on the release build configuration and not on debug. dyld[5274]: Symbol not found: _$s7SwiftUI17EnvironmentValuesV21_writingToolsBehaviorAA07WritingfG0VSgvg Referenced from: <1306655E-6DF7-3B2A-94A3-7202149E82F3> /private/var/containers/Bundle/Application/88E47904-4884-4279-9E96-0EC366970389/WritingToolsTest.app/WritingToolsTest Expected in: <165D3305-401E-37C2-8387-C1BFB54CFFDE> /System/Library/Frameworks/SwiftUI.framework/SwiftUI Feedback ID: FB17980516
0
0
129
Jun ’25
Bottom toolbar Button truncated on Mac Catalyst 26
On Mac Catalyst 26, a Button bar item in a bottom toolbar look squished. This happens only when the "Mac Catalyst Interface" option is set to "Optimize for Mac". When it is set to "Scale to match iPad", the buttons look fine. For example, in the screenshots below, the text button should say "Press Me", instead of "…" A simple reproducible snippet and a screenshot below. The toolbar button comparison between "Scale to match iPad" and "Optimize for Mac" are shown. Optimize for Mac Scale to match iPad import SwiftUI struct ContentView: View { @State private var selectedItem: String? = "Item 1" let items = ["Item 1", "Item 2"] var body: some View { NavigationSplitView { List(items, id: \.self, selection: $selectedItem) { item in Text(item) } .navigationTitle("Items") } detail: { if let selectedItem = selectedItem { Text("Detail view for \(selectedItem)") .toolbar { ToolbarItemGroup(placement: .bottomBar) { Text("Hello world") Spacer() Button("Press Me") { } Spacer() Button { } label: { Image(systemName: "plus") .imageScale(.large) } } } } else { Text("Select an item") } } } }
0
1
281
Oct ’25
How to apply SwiftUI window modifiers when using Xcode's #Preview on a macOS view?
Is there a way to configure the style and toolbar of the macOS window that Xcode uses in #Preview? I am working on a macOS application and want to preview some SwiftUI views within different window styles, toolbar styles and window title/subtitle visibilities. Some of the modifiers to control the look-and-feel of a window are actually Scene Modifiers, not View Modifiers: .windowStyle .windowToolbarLabelStyle .windowToolbarStyle But #Preview does not accept Scenes, so I can't apply these modifiers: // Error, not a view modifier. #Preview { ContentView() .windowStyle(...) } // Error, Window is not supported in #Preview. #Preview { Window("Browser", id: "browser") { ContentView() } } If I give my ContentView a .toolbar(...), Xcode's Preview will correctly show a window with a toolbar, but not necessarily in the style I want. Is there a way to apply the Scene Modifiers to #Preview so that I can see how they affect the window's chrome and toolbar?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
1
84
Oct ’25
Appearance of custom control changes depending on where it is used.
I made a custom SwiftUI control with two sliders trying to mimic the appearance of the new sliders in version 26 OSs. I was able to get something close to the way Apple's single slider looks and works. This is how it normally looks: And this is how it looks when one of the sliders is being dragged: This isn't perfect but I could live with it. Except that I want to use that control in a SwiftUI List, and by placing it in the list it doesn't have the same appearance though it functions the same. When the thumbs aren't being dragged it looks like this: Same as before which is great. But when one of the thumbs is being dragged it looks like this: Something about dropping the control into a List broke the transparency effect. All these screenshots were taken using the Xcode simulator for iOS. I achieved the transparency effect using .glassEffect(.clear.interactive(true)) on the thumb, along with a second capsule drawn on top when the thumb isn't being dragged. I needed the second capsule, if I messed with the one with the glass effect applied it would no longer scale when clicked and dragged. I have also tried placing the control inside a GlassEffectContainer at various levels of the hierarchy and it never improves the situation, instead the white capsule I draw on top turns a shade of gray. I tried other colors and it doesn't change those, only white. Why does my control lose transparency when I put it in a List, and more importantly how do I fix it?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
102
Oct ’25
Remove persistent bottom gray bar at the bottom when using hardware keyboard
DESCRIPTION OF PROBLEM When using SwiftUI’s TextField or TextEditor on iPadOS, a persistent gray or default system material bar appears at the bottom of the screen. This gray bar is not present in Apple’s native apps (such as Notes, Mail, Messages) or in third-party apps like ChatGPT and Beeper STEPS TO REPRODUCE Create a TextField or TextEditor. Run the code, click on it, without software keyboard enabled.
0
0
130
May ’25
UI Sounds visionOS
Hi, Looking to get secondary tap sound in UI, When in menus on visionOS there is a secondary sound that isn't a button sound when you tap on elements not - does anyone know how to add this sound (it's also in settings when you tap on any element? Currently I am generating a similar field as in the appstore settings but the onTapGesture doesn't make a system sound. Thanks! let title: String let subtitle: String? let action: (() -> Void)? @State private var isHovered = false init(title: String, subtitle: String? = nil, action: (() -> Void)? = nil) { self.title = title self.subtitle = subtitle self.action = action } var body: some View { HStack { VStack(alignment: .leading, spacing: 2) { Text(title) .font(.body) .foregroundColor(.primary) if let subtitle = subtitle { Text(subtitle) .font(.caption) .foregroundColor(.secondary) } } Spacer() Image(systemName: "chevron.right") .font(.system(size: 12, weight: .medium)) .foregroundColor(.secondary) } .padding(.horizontal, 24) .frame(height: 50.45) .background(.black.opacity(0.3)) .onTapGesture { action?() } .hoverEffect(.highlight) } }
0
0
102
Oct ’25
SwiftUI: Can a NavigationDestination in NavigationStack present the view as a .sheet instead of pushing?
Hi everyone, I’m experimenting with SwiftUI's new NavigationStack / navigationDestination API. Normally, when you navigate to a value using NavigationLink(value:) and a matching navigationDestination(for:), the destination view is pushed onto the navigation stack. What I’d like to know is: Is there a way to present that destination view as a sheet instead of pushing it? Essentially: Can a NavigationDestination be shown modally? Here’s a simplified example of what I mean: struct RootView: View { var body: some View { NavigationStack { NavigationLink(value: "Example") { Text("Push me!") } .navigationDestination(for: String.self) { _ in DetailView() // <--- Can this be shown as a sheet? } } } } My questions are: Is there a built‑in way to make a navigationDestination present modally (as .sheet) instead of pushing? If not, is the recommended approach to handle .sheet state manually outside of the NavigationStack and bypass navigationDestination for such cases? Can the NavigationPath itself somehow encode a modal presentation style for certain types? Thanks in advance for any tips or confirmation that this is (not) possible in SwiftUI.
0
0
109
Sep ’25
A focused searchable modifier breaks programmatic back navigation
Calls to NavigationPath.removeLast(_:) will successfully remove items from the path, but the navigation stack UI fails to correctly update if a view in an intermediate path item had a focused searchable modifier. In this first video, the searchable modifier is unused. I can navigate to the list, make a selection and return home: In this second example, the searchable modifier is focused and a selection from the list is made. In the final screen, if I attempt to return home we can see that the navigation path size decreases but the view does not change. If the button is pressed again, we attempt to remove path items that no longer exist, causing a fatal error. Minimal Reproducible Code: import SwiftUI @main struct NavigationStackRemoveLastNBugApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var navigationPath = NavigationPath() var body: some View { NavigationStack(path: $navigationPath) { List { Button("List") { navigationPath.append(NavigationDestination.listView) } } .navigationDestination(for: NavigationDestination.self) { destination in switch destination { case let .selectionView(int): SelectionView(selectedNumber: int) case .listView: ListView() } } .navigationTitle("Home") } .environment(\.navigationPath, $navigationPath) } } enum NavigationDestination: Hashable { case listView case selectionView(Int) } struct ListView: View { @Environment(\.navigationPath) var navigationPath @State private var query = "" var body: some View { List(1..<5, id: \.self) { int in Button { navigationPath?.wrappedValue.append(NavigationDestination.selectionView(int)) } label: { Text(int, format: .number) } } .searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always)) } } struct SelectionView: View { @Environment(\.navigationPath) var navigationPath let selectedNumber: Int @State private var pathSize: Int? var body: some View { List { LabeledContent("Selection", value: selectedNumber.formatted()) if let pathSize { LabeledContent("Navigation Path Size", value: pathSize.formatted()) } Button("Back Home") { navigationPath?.wrappedValue.removeLast(2) pathSize = navigationPath?.wrappedValue.count } } .task { pathSize = navigationPath?.wrappedValue.count } } } extension EnvironmentValues { @Entry var navigationPath: Binding<NavigationPath>? } #Preview { ContentView() } FB20395585
0
0
93
Sep ’25
Reading large documents
Can the SwiftUI document architecture Take a file as read-only; never to be written out Take files too large for memory (multi-MB, or even GB) I wouldn't want the system to read a gigabyte size file into memory by default. If the system can use a memory-mapped Data as the representation, that'll be something I can make do. It would be even better if I could tell the system that I'll handle all the reading, all I need from it is a reference to the file's location on disk.
Topic: UI Frameworks SubTopic: SwiftUI
0
0
52
Apr ’25
SCStreamUpdateFrameContentRect X coordinate always returns 48 instead of expected 0
SCStreamUpdateFrameContentRect X coordinate always returns 48 instead of expected 0 Environment Device: MacBook Pro 13-inch macOS: Sequoia 15.6.1 Xcode: 16.4 Framework: Screen Capture Kit Issue Description I'm experiencing an unexpected behavior with Screen Capture Kit where the SCStreamUpdateFrameContentRect X coordinate consistently returns 48 instead of the expected 0. Code Context I'm using SCContentSharingPicker to capture screen content and implementing the SCStreamOutput protocol to receive frame data. In my stream(_:didOutputSampleBuffer:of:) method, I'm extracting the content rect information from the sample buffer attachments: func stream(_ stream: SCStream, didOutputSampleBuffer sampleBuffer: CMSampleBuffer, of type: SCStreamOutputType) { switch type { case .screen: guard let attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, createIfNecessary: false) as? [[SCStreamFrameInfo: Any]] else { return } guard let attachments = attachmentsArray.first else { return } if !attachments.keys.contains(.contentRect) { return } print(attachments) // X coordinate always shows 48 /* , __C.SCStreamFrameInfo(_rawValue: SCStreamUpdateFrameContentRect): { Height = 540; Width = 864; X = 48; <<-- unexpected offset Y = 0; }] */ return // ... other cases } } Expected vs Actual Behavior Expected: X coordinate should be 0 (indicating the content starts at the left edge of the screen) Actual: X coordinate is consistently 48 Visual verification: When I display the captured screen content, it appears correctly without any offset, suggesting the actual content should indeed start at X=0 Additional Information The picker is configured with .singleDisplay mode I'm excluding the current app's bundle ID from capture The captured content visually appears correct, only the reported coordinates seem off Main ViewModel Class import Foundation import ScreenCaptureKit import SwiftUICore class VM: NSObject, ObservableObject, SCContentSharingPickerObserver, SCStreamDelegate, SCStreamOutput { @State var isRecording = false // Error handling delegate func stream(_ stream: SCStream, didStopWithError error: Error) { DispatchQueue.main.async { self.isRecording = false } } var picker: SCContentSharingPicker? func createPicker() -> SCContentSharingPicker { if let p = picker { return p } let picker = SCContentSharingPicker.shared picker.add(self) picker.isActive = true SCContentSharingPicker.shared.present(using: .display) return picker } var stream: SCStream? let videoSampleBufferQueue = DispatchQueue(label: "com.example.apple-samplecode.VideoSampleBufferQueue") // observer call back for picker func contentSharingPicker(_ picker: SCContentSharingPicker, didUpdateWith filter: SCContentFilter, for stream: SCStream?) { if let stream = stream { stream.updateContentFilter(filter) } else { let config = SCStreamConfiguration() config.capturesAudio = false config.captureMicrophone = false config.captureResolution = .automatic config.captureDynamicRange = .SDR config.showMouseClicks = false config.showsCursor = false // Set the frame rate for screen capture config.minimumFrameInterval = CMTime(value: 1, timescale: 5) // 10 FPS self.stream = SCStream(filter: filter, configuration: config, delegate: self) do { try self.stream?.addStreamOutput(self, type: .screen, sampleHandlerQueue: self.videoSampleBufferQueue) } catch { print("\(error)") } self.stream?.updateContentFilter(filter) DispatchQueue.main.async { self.stream?.startCapture() } } } func contentSharingPicker(_ picker: SCContentSharingPicker, didCancelFor stream: SCStream?) {} func contentSharingPickerStartDidFailWithError(_ error: any Error) { print(error) } func stream(_ stream: SCStream, didOutputSampleBuffer sampleBuffer: CMSampleBuffer, of type: SCStreamOutputType) { switch type { case .screen: guard let attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, createIfNecessary: false) as? [[SCStreamFrameInfo: Any]] else { return } guard let attachments = attachmentsArray.first else { return } if !attachments.keys.contains(.contentRect) { return } print(attachments) return case .audio: return case .microphone: return @unknown default: return } } func outputVideoEffectDidStart(for stream: SCStream) { print("outputVideoEffectDidStart") } func outputVideoEffectDidStop(for stream: SCStream) { print("outputVideoEffectDidStop") } func streamDidBecomeActive(_ stream: SCStream) { print("streamDidBecomeActive") } func streamDidBecomeInactive(_ stream: SCStream) { print("streamDidBecomeInactive") } }
0
0
81
Sep ’25
ScrollView paging position is off in iOS 26
Hi everyone, I have the following issue that I have tried to tweak every possible modifier of ScrollView and still got the same result in iOS 26. Description: Create a SwiftUI ScrollView with scrollTargetBehavior of paging, also create a bottom UI view below the ScrollView. If the starting index is not 0, the position of current page will be off with part of previous page shown above it. It only happens on iOS 26, not on iOS 18. Also if bottom UI view (text view in this case) is removed, it also works fine. I want to see if there is a solution for it or it's an iOS 26 bug. Thanks! import SwiftUI struct ContentView: View { @State private var currentPageIndex: Int? = 3 var body: some View { VStack { scrollView Text("Bottom Bar") .frame(maxWidth: .infinity) .frame(height: 80) .background(.red) } .background(.black) } @ViewBuilder var scrollView: some View { VerticalPagerView( currentPageIndex: $currentPageIndex, itemCount: 10, content: Array(0...9).map { index in content(for: index) } ) } @ViewBuilder private func content(for index: Int) -> some View { // Empty view with random background color Color( red: Double((index * 25 + 0) % 255) / 255.0, green: Double((index * 25 + 80) % 255) / 255.0, blue: Double((index * 25 + 160) % 255) / 255.0 ) } } struct VerticalPagerView<Content: View>: View { @Binding private var currentPageIndex: Int? private let itemCount: Int private let content: [Content] init( currentPageIndex: Binding<Int?>, itemCount: Int, content: [Content] ) { self._currentPageIndex = currentPageIndex self.itemCount = itemCount self.content = content } var body: some View { GeometryReader { geometryReader in ScrollViewReader { reader in ScrollView(.vertical) { LazyVStack(spacing: 0) { ForEach(0 ..< itemCount, id: \.self) { index in content[index] .id(index) .containerRelativeFrame(.vertical, alignment: .center) .clipped() } } .frame(minHeight: geometryReader.size.height) .scrollTargetLayout() } .scrollIndicators(.hidden) .onAppear { guard let currentPageIndex = currentPageIndex else { return } reader.scrollTo(currentPageIndex, anchor: .center) } } .scrollPosition(id: $currentPageIndex, anchor: .center) .ignoresSafeArea() .scrollTargetBehavior(.paging) .onChange(of: currentPageIndex) { oldIndex, newIndex in } } } }
0
2
246
Sep ’25
Showing space .navigationTitle leads to unexpected results.
I wanted to set navigationTitle value to space symbol on my iOS app (Swift 6, iOS 26.0) (so that navigationBar opens in large mode initially before the actual value is being fetched). In my view I used this: .navigationTitle(" ") And on device I got unexpectedly two quote symbols: Not sure if there is space in between, and the symbols look like opening and closing quote (both quotes in code I think are the same symbols) - so probably it's not part of my code is visible in UI as one might think... . Is this a bug? Or undocumented feature?
0
1
123
Sep ’25
SwiftUI TextField selects all text when it gains focus — how to move caret to the end like in AppKit?
I’m running into an issue with TextField focus behavior in SwiftUI. By default, when I set focus to a TextField programmatically (using @FocusState), SwiftUI behaves like AppKit — the entire contents of the text field are selected. This is causing problems for my use case, because I want the caret placed at the end of the text without selecting everything. How I solved this in AppKit In AppKit, I worked around this by subclassing NSTextField and overriding becomeFirstResponder to adjust the editor’s selection: override func becomeFirstResponder() -> Bool { let responderStatus = super.becomeFirstResponder() // Ensure caret is placed at the end, no text selected if let editor = self.currentEditor() { let selectedRange = editor.selectedRange editor.selectedRange = NSRange(location: selectedRange.length, length: 0) } return responderStatus } This successfully prevented AppKit from auto-selecting the entire string when focus changed. The problem in SwiftUI Now I see the same auto-select behavior in SwiftUI when I toggle focus with @FocusState. But unlike AppKit, SwiftUI doesn’t expose the underlying NSTextView or UITextField APIs, so I can’t directly adjust the selection or caret position. Questions: Is there a way in SwiftUI to control the caret/selection behavior when a TextField becomes focused? Is there a built-in modifier or @FocusState trick I’m missing? Has anyone found a reliable SwiftUI-idiomatic approach to ensure the caret is placed at the end of the text instead of selecting all text? update: adding my swiftUI code below: struct TextFieldUI: View { @ObservedObject var pModel:TextFieldModel @FocusState private var pIsFocusedState: Bool var body: some View { VStack(spacing: 20) { TextField(pModel.placeholder, text: $pModel.text) .textFieldStyle(RoundedBorderTextFieldStyle()) .padding() .focused($pIsFocusedState) .onChange(of: pModel.isFocused) { old, newValue in pIsFocusedState = newValue } .onChange(of: pIsFocusedState) { old, newValue in pModel.isFocused = newValue } .onAppear { pIsFocusedState = pModel.isFocused } Toggle("Secure Mode", isOn: $pModel.isSecure) .padding() } .padding() } }
0
0
128
Sep ’25
Sorting of FetchResults in TableView broken in xcode 26
Previously, I sorted my FetchResult in a TableView like this: @FetchRequest( sortDescriptors: [SortDescriptor(\.rechnungsDatum, order: .forward)], predicate: NSPredicate(format: "betragEingang == nil OR betragEingang == 0") ) private var verguetungsantraege: FetchedResults&lt;VerguetungsAntraege&gt; ... body ... Table(of:VerguetungsAntraege.self, sortOrder: $verguetungsantraege.sortDescriptors) { TableColumn("date", value:\.rechnungsDatum) { item in Text(Formatters.dateFormatter.string(from: item.rechnungsDatum ?? Date()) ) } .width(120) TableColumn("rechNrKurz", value:\.rechnungsNummer) { item in Text(item.rechnungsNummer ?? "") } .width(120) TableColumn("betrag", value:\.totalSum ) { Text(Formatters.currencyFormatter.string(from: $0.totalSum as NSNumber) ?? "kein Wert") } .width(120) TableColumn("klient") { Text(db.getKlientNameByUUID(id: $0.klient ?? UUID(), moc: moc)) } } rows: { ForEach(Array(verguetungsantraege)) { antrag in TableRow(antrag) } } There seem to be changes here in Xcode 26. In any case, I always get the error message in each line with TableColumn("title", value: \.sortingField) Ambiguous use of 'init(_:value:content:)' Does anyone have any idea what's changed? Unfortunately, the documentation doesn't provide any information.
Replies
0
Boosts
0
Views
175
Activity
Jun ’25
NavigationPath.append but .navigationDestination Not Being Called
I am trying to do a bit of fancy navigation in SwiftUI using NavigationPath and am having a problem. I have a root view with includes a button: struct ClassListScreen: View { @Bindable private var router = AppRouter.shared @State private var addCourse: Bool = false ... var body: some View { ... Button("Add Class") { router.currentPath.append(addCourse) }.buttonStyle(.borderedProminent) ... .navigationDestination(for: Bool.self){ _ in ClassAddDialog { course in sortCourses() } } } } router.currentPath is the NavigationPath associated with the operative NavigationStack. (This app has a TabView and each Tab has its own NavigationStack and NavigationPath). Tapping the button correctly opens the ClassAddDialog. In ClassAddDialog is another button: struct ClassAddDialog: View { @Bindable private var router = AppRouter.shared @State private var idString: String = "" ... var body: some View { ... Button("Save") { let course = ... ... (save logic) idString = course.id.uuidString var path = router.currentPath path.removeLast() path.append(idString) router.currentPath = path }.buttonStyle(.borderedProminent) ... .navigationDestination(for: String.self) { str in if let id = UUID(uuidString: str), let course = Course.findByID(id, with: context) { ClassDetailScreen(course: course) } } } } My intent here is that tapping the Save button in ClassAddDialog would pop that view and move directly to the ClassDetailScreen (without returning to the root ClassListScreen). The problem is that the code inside the navigationDestination is NEVER hit. (I.e., a breakpoint on the if let ... statement) never fires. I just end up on a (nearly) blank view with a warning triangle icon in its center. (And yes, the back button takes me to the root, so the ClassAddDialog WAS removed as expected.) And I don't understand why. Can anyone share any insight here?
Replies
0
Boosts
1
Views
105
Activity
Oct ’25
unable to click when ZoomNavigationTransition finished
I am using ".navigationTransition(ZoomNavigationTransition.zoom(sourceID: xxx, in: xxx))" to zooms the appearing view from a source view . When the appearing view dismissed, I can only click other view after a delay . It seems that the transition is not finished immediately when the appearing view dismissed . After a delay, the transition finished, than I can click other view. struct ContentView: View { @State private var path: NavigationPath = NavigationPath() @Namespace private var namespace var body: some View { NavigationStack(path: $path) { VStack(spacing: 0) { ForEach(["aaa", "bbb"], id: \.self) { string in Text(string) .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2) .contentShape(Rectangle()) .onTapGesture { path.append(string) } .matchedTransitionSource(id: string, in: namespace) } } .navigationDestination(for: String.self, destination: { route in Text(route) .navigationTransition(ZoomNavigationTransition.zoom(sourceID: route, in: namespace)) }) } } } When using sheet on appearing view, It seems that the transition is finished immediately when the appearing view dismissed. extension String: Identifiable { public var id: String { return self } } struct ContentView: View { @State private var path: NavigationPath = NavigationPath() @Namespace private var namespace @State private var stringToSheet: String? var body: some View { NavigationStack(path: $path) { VStack(spacing: 0) { ForEach(["aaa", "bbb"], id: \.self) { string in Text(string) .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2) .contentShape(Rectangle()) .onTapGesture { stringToSheet = string } .matchedTransitionSource(id: string, in: namespace) } } .sheet(item: $stringToSheet) { newValue in Text(newValue) .navigationTransition(ZoomNavigationTransition.zoom(sourceID: newValue, in: namespace)) } } } }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
75
Activity
Jun ’25
When is the StateObject’s autoclosure actually called?
The signature of the StateObject initializer is init(wrappedValue thunk: @autoclosure @escaping () -> ObjectType). The fact that the autoclosure is marked as escaping intrigues me, because that suggests that it could be called after the init has returned. Why this is interesting is because I have some code where the viewmodel given to the @StateObject depends on an implicitly unwrapped optional type, and I expect the top level initialization of the StateObject to crash because the implicitly unwrapped optional is not ready yet, but to my surprise it did not. My theory is that the autoclosure is being called after the View’s initialization had been called, when the dependency is ready. heres a minimal sample of that. class MyDependency: ObservableObject { @Published var value = "Hello" } class MyViewModel: ObservableObject { let dependency: MyDependency init(dependency: MyDependency = TestApp.dependency) { self.dependency = dependency print("✅ ViewModel initialized with dependency:", dependency.value) } } struct ContentView: View { @StateObject private var viewModel = MyViewModel() // ⚠️ expected crash? var body: some View { Text(viewModel.dependency.value).onAppear { TestApp.dependency = Dependency()// dependency is set here after init has been called } } } @main struct TestApp: App { static var dependency: MyDependency! // not ready yet var body: some Scene { WindowGroup { ContentView() } }```
Replies
0
Boosts
0
Views
135
Activity
Oct ’25
Document-based app: file picker flickers since macOS 26 update
Description: Since updating to Tahoe, the file picker dialog briefly flickers immediately after opening in my document-based app. This behavior did not occur on macOS Sequoia. Rhe issue does not appear in TextEdit, but it does occur in Paper (a writing app) and Kaleidoscope. Based on this, it seems to affect third-party document-based apps that use standard open panels. Steps to Reproduce: 1. Launch a third-party document-based app. 2. Open the file picker (e.g., via “Open…”). 3. Observe a brief flicker as the dialog appears. Expected Result: The file picker dialog should open smoothly without flickering. Actual Result: The file picker dialog flickers briefly right after appearing. Notes: • Issue introduced in macOS Tahoe. • Not reproducible in macOS Sequoia. Reported through Feedback Assistant: FB20522119
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
0
Boosts
0
Views
149
Activity
Oct ’25
Unknown error when displaying IntentItems with images in widget configuration intent
Hi everyone, I’m building a simple sticky notes app that allows users to place a note widget on their home screen. Each widget displays a user-created sticky note. To let users choose which note to show, I’ve implemented an Intent that presents a list of existing sticky notes. The list is built using IntentItems, and for each item I assign an image to visually represent the note. Each sticky note can have a different background color and optional image, so I generate a small PNG (150×150, ~30 KB) and include it in the app bundle. However, when I try to display the selection list, I get the following error: The action Select sticky note could not run because an unknown error occurred. If I tap OK and try again, the intent selector appears and works. Here’s what I’d like to understand: What could cause this unknown error when using images in IntentItems? Are there known limitations on image size, source, or format for intent item images? Can I supply a unique image per sticky note, or must all intent items share a common image? Any guidance or insights would be greatly appreciated — I haven’t been able to find clear documentation about image handling in IntentItem for widget configuration. Thanks!
Replies
0
Boosts
0
Views
112
Activity
Oct ’25
Symbol not found error when using writingToolsBehavior API built with Xcode 26 and run on iOS 18
When using the writingToolsBehavior API on a TextField and the app compiled with the iOS 26 SDK is run on an iOS 18 device, the app crashes with a symbol not found error. It only crashes on the release build configuration and not on debug. dyld[5274]: Symbol not found: _$s7SwiftUI17EnvironmentValuesV21_writingToolsBehaviorAA07WritingfG0VSgvg Referenced from: <1306655E-6DF7-3B2A-94A3-7202149E82F3> /private/var/containers/Bundle/Application/88E47904-4884-4279-9E96-0EC366970389/WritingToolsTest.app/WritingToolsTest Expected in: <165D3305-401E-37C2-8387-C1BFB54CFFDE> /System/Library/Frameworks/SwiftUI.framework/SwiftUI Feedback ID: FB17980516
Replies
0
Boosts
0
Views
129
Activity
Jun ’25
Bottom toolbar Button truncated on Mac Catalyst 26
On Mac Catalyst 26, a Button bar item in a bottom toolbar look squished. This happens only when the "Mac Catalyst Interface" option is set to "Optimize for Mac". When it is set to "Scale to match iPad", the buttons look fine. For example, in the screenshots below, the text button should say "Press Me", instead of "…" A simple reproducible snippet and a screenshot below. The toolbar button comparison between "Scale to match iPad" and "Optimize for Mac" are shown. Optimize for Mac Scale to match iPad import SwiftUI struct ContentView: View { @State private var selectedItem: String? = "Item 1" let items = ["Item 1", "Item 2"] var body: some View { NavigationSplitView { List(items, id: \.self, selection: $selectedItem) { item in Text(item) } .navigationTitle("Items") } detail: { if let selectedItem = selectedItem { Text("Detail view for \(selectedItem)") .toolbar { ToolbarItemGroup(placement: .bottomBar) { Text("Hello world") Spacer() Button("Press Me") { } Spacer() Button { } label: { Image(systemName: "plus") .imageScale(.large) } } } } else { Text("Select an item") } } } }
Replies
0
Boosts
1
Views
281
Activity
Oct ’25
How to apply SwiftUI window modifiers when using Xcode's #Preview on a macOS view?
Is there a way to configure the style and toolbar of the macOS window that Xcode uses in #Preview? I am working on a macOS application and want to preview some SwiftUI views within different window styles, toolbar styles and window title/subtitle visibilities. Some of the modifiers to control the look-and-feel of a window are actually Scene Modifiers, not View Modifiers: .windowStyle .windowToolbarLabelStyle .windowToolbarStyle But #Preview does not accept Scenes, so I can't apply these modifiers: // Error, not a view modifier. #Preview { ContentView() .windowStyle(...) } // Error, Window is not supported in #Preview. #Preview { Window("Browser", id: "browser") { ContentView() } } If I give my ContentView a .toolbar(...), Xcode's Preview will correctly show a window with a toolbar, but not necessarily in the style I want. Is there a way to apply the Scene Modifiers to #Preview so that I can see how they affect the window's chrome and toolbar?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
0
Boosts
1
Views
84
Activity
Oct ’25
Appearance of custom control changes depending on where it is used.
I made a custom SwiftUI control with two sliders trying to mimic the appearance of the new sliders in version 26 OSs. I was able to get something close to the way Apple's single slider looks and works. This is how it normally looks: And this is how it looks when one of the sliders is being dragged: This isn't perfect but I could live with it. Except that I want to use that control in a SwiftUI List, and by placing it in the list it doesn't have the same appearance though it functions the same. When the thumbs aren't being dragged it looks like this: Same as before which is great. But when one of the thumbs is being dragged it looks like this: Something about dropping the control into a List broke the transparency effect. All these screenshots were taken using the Xcode simulator for iOS. I achieved the transparency effect using .glassEffect(.clear.interactive(true)) on the thumb, along with a second capsule drawn on top when the thumb isn't being dragged. I needed the second capsule, if I messed with the one with the glass effect applied it would no longer scale when clicked and dragged. I have also tried placing the control inside a GlassEffectContainer at various levels of the hierarchy and it never improves the situation, instead the white capsule I draw on top turns a shade of gray. I tried other colors and it doesn't change those, only white. Why does my control lose transparency when I put it in a List, and more importantly how do I fix it?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
102
Activity
Oct ’25
Remove persistent bottom gray bar at the bottom when using hardware keyboard
DESCRIPTION OF PROBLEM When using SwiftUI’s TextField or TextEditor on iPadOS, a persistent gray or default system material bar appears at the bottom of the screen. This gray bar is not present in Apple’s native apps (such as Notes, Mail, Messages) or in third-party apps like ChatGPT and Beeper STEPS TO REPRODUCE Create a TextField or TextEditor. Run the code, click on it, without software keyboard enabled.
Replies
0
Boosts
0
Views
130
Activity
May ’25
UI Sounds visionOS
Hi, Looking to get secondary tap sound in UI, When in menus on visionOS there is a secondary sound that isn't a button sound when you tap on elements not - does anyone know how to add this sound (it's also in settings when you tap on any element? Currently I am generating a similar field as in the appstore settings but the onTapGesture doesn't make a system sound. Thanks! let title: String let subtitle: String? let action: (() -> Void)? @State private var isHovered = false init(title: String, subtitle: String? = nil, action: (() -> Void)? = nil) { self.title = title self.subtitle = subtitle self.action = action } var body: some View { HStack { VStack(alignment: .leading, spacing: 2) { Text(title) .font(.body) .foregroundColor(.primary) if let subtitle = subtitle { Text(subtitle) .font(.caption) .foregroundColor(.secondary) } } Spacer() Image(systemName: "chevron.right") .font(.system(size: 12, weight: .medium)) .foregroundColor(.secondary) } .padding(.horizontal, 24) .frame(height: 50.45) .background(.black.opacity(0.3)) .onTapGesture { action?() } .hoverEffect(.highlight) } }
Replies
0
Boosts
0
Views
102
Activity
Oct ’25
SwiftUI: Can a NavigationDestination in NavigationStack present the view as a .sheet instead of pushing?
Hi everyone, I’m experimenting with SwiftUI's new NavigationStack / navigationDestination API. Normally, when you navigate to a value using NavigationLink(value:) and a matching navigationDestination(for:), the destination view is pushed onto the navigation stack. What I’d like to know is: Is there a way to present that destination view as a sheet instead of pushing it? Essentially: Can a NavigationDestination be shown modally? Here’s a simplified example of what I mean: struct RootView: View { var body: some View { NavigationStack { NavigationLink(value: "Example") { Text("Push me!") } .navigationDestination(for: String.self) { _ in DetailView() // <--- Can this be shown as a sheet? } } } } My questions are: Is there a built‑in way to make a navigationDestination present modally (as .sheet) instead of pushing? If not, is the recommended approach to handle .sheet state manually outside of the NavigationStack and bypass navigationDestination for such cases? Can the NavigationPath itself somehow encode a modal presentation style for certain types? Thanks in advance for any tips or confirmation that this is (not) possible in SwiftUI.
Replies
0
Boosts
0
Views
109
Activity
Sep ’25
A focused searchable modifier breaks programmatic back navigation
Calls to NavigationPath.removeLast(_:) will successfully remove items from the path, but the navigation stack UI fails to correctly update if a view in an intermediate path item had a focused searchable modifier. In this first video, the searchable modifier is unused. I can navigate to the list, make a selection and return home: In this second example, the searchable modifier is focused and a selection from the list is made. In the final screen, if I attempt to return home we can see that the navigation path size decreases but the view does not change. If the button is pressed again, we attempt to remove path items that no longer exist, causing a fatal error. Minimal Reproducible Code: import SwiftUI @main struct NavigationStackRemoveLastNBugApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var navigationPath = NavigationPath() var body: some View { NavigationStack(path: $navigationPath) { List { Button("List") { navigationPath.append(NavigationDestination.listView) } } .navigationDestination(for: NavigationDestination.self) { destination in switch destination { case let .selectionView(int): SelectionView(selectedNumber: int) case .listView: ListView() } } .navigationTitle("Home") } .environment(\.navigationPath, $navigationPath) } } enum NavigationDestination: Hashable { case listView case selectionView(Int) } struct ListView: View { @Environment(\.navigationPath) var navigationPath @State private var query = "" var body: some View { List(1..<5, id: \.self) { int in Button { navigationPath?.wrappedValue.append(NavigationDestination.selectionView(int)) } label: { Text(int, format: .number) } } .searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always)) } } struct SelectionView: View { @Environment(\.navigationPath) var navigationPath let selectedNumber: Int @State private var pathSize: Int? var body: some View { List { LabeledContent("Selection", value: selectedNumber.formatted()) if let pathSize { LabeledContent("Navigation Path Size", value: pathSize.formatted()) } Button("Back Home") { navigationPath?.wrappedValue.removeLast(2) pathSize = navigationPath?.wrappedValue.count } } .task { pathSize = navigationPath?.wrappedValue.count } } } extension EnvironmentValues { @Entry var navigationPath: Binding<NavigationPath>? } #Preview { ContentView() } FB20395585
Replies
0
Boosts
0
Views
93
Activity
Sep ’25
Reading large documents
Can the SwiftUI document architecture Take a file as read-only; never to be written out Take files too large for memory (multi-MB, or even GB) I wouldn't want the system to read a gigabyte size file into memory by default. If the system can use a memory-mapped Data as the representation, that'll be something I can make do. It would be even better if I could tell the system that I'll handle all the reading, all I need from it is a reference to the file's location on disk.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
52
Activity
Apr ’25
I used colorpick on the view, but after converting it to a entity, colorpick doesn't work. Is there any way to use colorpick
I used colorpick on the view, but after converting it to a model, colorpick doesn't work. Is there any way to use colorpick
Replies
0
Boosts
0
Views
80
Activity
Oct ’25
SCStreamUpdateFrameContentRect X coordinate always returns 48 instead of expected 0
SCStreamUpdateFrameContentRect X coordinate always returns 48 instead of expected 0 Environment Device: MacBook Pro 13-inch macOS: Sequoia 15.6.1 Xcode: 16.4 Framework: Screen Capture Kit Issue Description I'm experiencing an unexpected behavior with Screen Capture Kit where the SCStreamUpdateFrameContentRect X coordinate consistently returns 48 instead of the expected 0. Code Context I'm using SCContentSharingPicker to capture screen content and implementing the SCStreamOutput protocol to receive frame data. In my stream(_:didOutputSampleBuffer:of:) method, I'm extracting the content rect information from the sample buffer attachments: func stream(_ stream: SCStream, didOutputSampleBuffer sampleBuffer: CMSampleBuffer, of type: SCStreamOutputType) { switch type { case .screen: guard let attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, createIfNecessary: false) as? [[SCStreamFrameInfo: Any]] else { return } guard let attachments = attachmentsArray.first else { return } if !attachments.keys.contains(.contentRect) { return } print(attachments) // X coordinate always shows 48 /* , __C.SCStreamFrameInfo(_rawValue: SCStreamUpdateFrameContentRect): { Height = 540; Width = 864; X = 48; <<-- unexpected offset Y = 0; }] */ return // ... other cases } } Expected vs Actual Behavior Expected: X coordinate should be 0 (indicating the content starts at the left edge of the screen) Actual: X coordinate is consistently 48 Visual verification: When I display the captured screen content, it appears correctly without any offset, suggesting the actual content should indeed start at X=0 Additional Information The picker is configured with .singleDisplay mode I'm excluding the current app's bundle ID from capture The captured content visually appears correct, only the reported coordinates seem off Main ViewModel Class import Foundation import ScreenCaptureKit import SwiftUICore class VM: NSObject, ObservableObject, SCContentSharingPickerObserver, SCStreamDelegate, SCStreamOutput { @State var isRecording = false // Error handling delegate func stream(_ stream: SCStream, didStopWithError error: Error) { DispatchQueue.main.async { self.isRecording = false } } var picker: SCContentSharingPicker? func createPicker() -> SCContentSharingPicker { if let p = picker { return p } let picker = SCContentSharingPicker.shared picker.add(self) picker.isActive = true SCContentSharingPicker.shared.present(using: .display) return picker } var stream: SCStream? let videoSampleBufferQueue = DispatchQueue(label: "com.example.apple-samplecode.VideoSampleBufferQueue") // observer call back for picker func contentSharingPicker(_ picker: SCContentSharingPicker, didUpdateWith filter: SCContentFilter, for stream: SCStream?) { if let stream = stream { stream.updateContentFilter(filter) } else { let config = SCStreamConfiguration() config.capturesAudio = false config.captureMicrophone = false config.captureResolution = .automatic config.captureDynamicRange = .SDR config.showMouseClicks = false config.showsCursor = false // Set the frame rate for screen capture config.minimumFrameInterval = CMTime(value: 1, timescale: 5) // 10 FPS self.stream = SCStream(filter: filter, configuration: config, delegate: self) do { try self.stream?.addStreamOutput(self, type: .screen, sampleHandlerQueue: self.videoSampleBufferQueue) } catch { print("\(error)") } self.stream?.updateContentFilter(filter) DispatchQueue.main.async { self.stream?.startCapture() } } } func contentSharingPicker(_ picker: SCContentSharingPicker, didCancelFor stream: SCStream?) {} func contentSharingPickerStartDidFailWithError(_ error: any Error) { print(error) } func stream(_ stream: SCStream, didOutputSampleBuffer sampleBuffer: CMSampleBuffer, of type: SCStreamOutputType) { switch type { case .screen: guard let attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, createIfNecessary: false) as? [[SCStreamFrameInfo: Any]] else { return } guard let attachments = attachmentsArray.first else { return } if !attachments.keys.contains(.contentRect) { return } print(attachments) return case .audio: return case .microphone: return @unknown default: return } } func outputVideoEffectDidStart(for stream: SCStream) { print("outputVideoEffectDidStart") } func outputVideoEffectDidStop(for stream: SCStream) { print("outputVideoEffectDidStop") } func streamDidBecomeActive(_ stream: SCStream) { print("streamDidBecomeActive") } func streamDidBecomeInactive(_ stream: SCStream) { print("streamDidBecomeInactive") } }
Replies
0
Boosts
0
Views
81
Activity
Sep ’25
ScrollView paging position is off in iOS 26
Hi everyone, I have the following issue that I have tried to tweak every possible modifier of ScrollView and still got the same result in iOS 26. Description: Create a SwiftUI ScrollView with scrollTargetBehavior of paging, also create a bottom UI view below the ScrollView. If the starting index is not 0, the position of current page will be off with part of previous page shown above it. It only happens on iOS 26, not on iOS 18. Also if bottom UI view (text view in this case) is removed, it also works fine. I want to see if there is a solution for it or it's an iOS 26 bug. Thanks! import SwiftUI struct ContentView: View { @State private var currentPageIndex: Int? = 3 var body: some View { VStack { scrollView Text("Bottom Bar") .frame(maxWidth: .infinity) .frame(height: 80) .background(.red) } .background(.black) } @ViewBuilder var scrollView: some View { VerticalPagerView( currentPageIndex: $currentPageIndex, itemCount: 10, content: Array(0...9).map { index in content(for: index) } ) } @ViewBuilder private func content(for index: Int) -> some View { // Empty view with random background color Color( red: Double((index * 25 + 0) % 255) / 255.0, green: Double((index * 25 + 80) % 255) / 255.0, blue: Double((index * 25 + 160) % 255) / 255.0 ) } } struct VerticalPagerView<Content: View>: View { @Binding private var currentPageIndex: Int? private let itemCount: Int private let content: [Content] init( currentPageIndex: Binding<Int?>, itemCount: Int, content: [Content] ) { self._currentPageIndex = currentPageIndex self.itemCount = itemCount self.content = content } var body: some View { GeometryReader { geometryReader in ScrollViewReader { reader in ScrollView(.vertical) { LazyVStack(spacing: 0) { ForEach(0 ..< itemCount, id: \.self) { index in content[index] .id(index) .containerRelativeFrame(.vertical, alignment: .center) .clipped() } } .frame(minHeight: geometryReader.size.height) .scrollTargetLayout() } .scrollIndicators(.hidden) .onAppear { guard let currentPageIndex = currentPageIndex else { return } reader.scrollTo(currentPageIndex, anchor: .center) } } .scrollPosition(id: $currentPageIndex, anchor: .center) .ignoresSafeArea() .scrollTargetBehavior(.paging) .onChange(of: currentPageIndex) { oldIndex, newIndex in } } } }
Replies
0
Boosts
2
Views
246
Activity
Sep ’25
Showing space .navigationTitle leads to unexpected results.
I wanted to set navigationTitle value to space symbol on my iOS app (Swift 6, iOS 26.0) (so that navigationBar opens in large mode initially before the actual value is being fetched). In my view I used this: .navigationTitle(" ") And on device I got unexpectedly two quote symbols: Not sure if there is space in between, and the symbols look like opening and closing quote (both quotes in code I think are the same symbols) - so probably it's not part of my code is visible in UI as one might think... . Is this a bug? Or undocumented feature?
Replies
0
Boosts
1
Views
123
Activity
Sep ’25
SwiftUI TextField selects all text when it gains focus — how to move caret to the end like in AppKit?
I’m running into an issue with TextField focus behavior in SwiftUI. By default, when I set focus to a TextField programmatically (using @FocusState), SwiftUI behaves like AppKit — the entire contents of the text field are selected. This is causing problems for my use case, because I want the caret placed at the end of the text without selecting everything. How I solved this in AppKit In AppKit, I worked around this by subclassing NSTextField and overriding becomeFirstResponder to adjust the editor’s selection: override func becomeFirstResponder() -> Bool { let responderStatus = super.becomeFirstResponder() // Ensure caret is placed at the end, no text selected if let editor = self.currentEditor() { let selectedRange = editor.selectedRange editor.selectedRange = NSRange(location: selectedRange.length, length: 0) } return responderStatus } This successfully prevented AppKit from auto-selecting the entire string when focus changed. The problem in SwiftUI Now I see the same auto-select behavior in SwiftUI when I toggle focus with @FocusState. But unlike AppKit, SwiftUI doesn’t expose the underlying NSTextView or UITextField APIs, so I can’t directly adjust the selection or caret position. Questions: Is there a way in SwiftUI to control the caret/selection behavior when a TextField becomes focused? Is there a built-in modifier or @FocusState trick I’m missing? Has anyone found a reliable SwiftUI-idiomatic approach to ensure the caret is placed at the end of the text instead of selecting all text? update: adding my swiftUI code below: struct TextFieldUI: View { @ObservedObject var pModel:TextFieldModel @FocusState private var pIsFocusedState: Bool var body: some View { VStack(spacing: 20) { TextField(pModel.placeholder, text: $pModel.text) .textFieldStyle(RoundedBorderTextFieldStyle()) .padding() .focused($pIsFocusedState) .onChange(of: pModel.isFocused) { old, newValue in pIsFocusedState = newValue } .onChange(of: pIsFocusedState) { old, newValue in pModel.isFocused = newValue } .onAppear { pIsFocusedState = pModel.isFocused } Toggle("Secure Mode", isOn: $pModel.isSecure) .padding() } .padding() } }
Replies
0
Boosts
0
Views
128
Activity
Sep ’25