Discuss the different user interface frameworks available for your app.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

Layout Engine Crash on iOS 26: NSInternalInconsistencyException
Starting with iOS 26 beta, I'm encountering an intermittent crash in production builds related to Auto Layout and background threading. This crash did not occur on iOS 18 or earlier and has become reproducible only on devices running iOS 26 betas. We have already performed a thorough audit of our code: • Verified that all UIKit view hierarchy and layout mutations occur on the main thread. • Re-tested with strict logging—confirmed all remaining layout/constraint/view updates are performed on the main thread. • No third-party UI SDKs are used in the relevant flow. Despite that, the crash still occurs and always from a background thread, during internal UIKit layout commits. Fatal Exception: NSInternalInconsistencyException Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread. 0 MyApp 0x7adbc8 FIRCLSProcessRecordAllThreads + 172 1 MyApp 0x7adfd4 FIRCLSProcessRecordAllThreads + 1208 2 MyApp 0x7bc4b4 FIRCLSHandler + 56 3 MyApp 0x7bc25c __FIRCLSExceptionRecord_block_invoke + 100 4 libdispatch.dylib 0x1b7cc _dispatch_client_callout + 16 5 libdispatch.dylib 0x118a0 _dispatch_lane_barrier_sync_invoke_and_complete + 56 6 MyApp 0x7bb1f0 FIRCLSExceptionRecord + 224 7 MyApp 0x7bbd1c FIRCLSExceptionRecordNSException + 456 8 MyApp 0x7badf4 FIRCLSTerminateHandler() + 396 9 Intercom 0x86684 IntercomSDK_sentrycrashcm_cppexception_getAPI + 308 10 libc++abi.dylib 0x11bdc std::__terminate(void (*)()) + 16 11 libc++abi.dylib 0x15314 __cxa_get_exception_ptr + 86 12 libc++abi.dylib 0x152bc __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 90 13 libobjc.A.dylib 0x3190c objc_exception_throw + 448 14 CoreAutoLayout 0x13a4 -[NSISEngine optimize] + 314 15 CoreAutoLayout 0x1734 -[NSISEngine _optimizeWithoutRebuilding] + 72 16 CoreAutoLayout 0x1404 -[NSISEngine optimize] + 96 17 CoreAutoLayout 0xee8 -[NSISEngine performPendingChangeNotifications] + 104 18 UIKitCore 0x27ac8 -[UIView(Hierarchy) layoutSubviews] + 136 19 UIKitCore 0xfe760 -[UIWindow layoutSubviews] + 68 20 UIKitCore 0x234228 -[UITextEffectsWindow layoutSubviews] + 44 21 UIKitCore 0x27674 -[UIImageView animationImages] + 912 22 UIKitCore 0x28134 -[UIView(Internal) _viewControllerToNotifyOnLayoutSubviews] + 40 23 UIKitCore 0x18c2898 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2532 24 QuartzCore 0xabd98 CA::Layer::perform_update_(CA::Layer*, CALayer*, unsigned int, CA::Transaction*) + 116 25 QuartzCore 0x8e810 CA::Layer::update_if_needed(CA::Transaction*, unsigned int, unsigned int) + 600 26 QuartzCore 0xad45c CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 200 27 QuartzCore 0x6e30c CA::Context::commit_transaction(CA::Transaction*, double, double*) + 540 28 QuartzCore 0x9afc4 CA::Transaction::commit() + 644 29 QuartzCore 0x16974c CA::Transaction::release_thread(void*) + 180 30 libsystem_pthread.dylib 0x4c28 _pthread_tsd_cleanup + 620 31 libsystem_pthread.dylib 0x4998 _pthread_exit + 84 32 libsystem_pthread.dylib 0x5e3c pthread_atfork + 54 33 libsystem_pthread.dylib 0x1440 _pthread_wqthread + 428 34 libsystem_pthread.dylib 0x8c0 start_wqthread + 8 Any ideas?
2
1
175
2d
Clarification on Using Secure UITextField to Prevent Screen Capture
Hello Developer Forums Team, I’ve seen that some banking apps prevent screenshots on certain sensitive screens. I’m working on a similar feature in my SDK and want to confirm if my implementation complies with App Store guidelines. Since there’s no public API to block screenshots, I’m using a workaround based on the secure rendering behavior of UITextField (isSecureTextEntry = true). I embed my custom content (e.g., a UITableView) inside the internal secure container of a UITextField, which results in blank content being captured during screenshots—similar to what some banking apps do. Approach Summary I create a UITextField I detect its internal secure container by matching UIKit internal class names as strings I embed my real UI content into that container I do not use or call any private APIs, just match view class names via strings. ScreenshotPreventingView.swift final class ScreenshotPreventingView: UIView { private let textField = UITextField() private let recognizer = HiddenContainerRecognizer() private var contentView: UIView? public var preventScreenCapture = true { didSet { textField.isSecureTextEntry = preventScreenCapture } } public init(contentView: UIView? = nil) { super.init(frame: .zero) self.contentView = contentView setupUI() } private func setupUI() { guard let container = try? recognizer.getHiddenContainer(from: textField) else { return } addSubview(container) NSLayoutConstraint.activate([ container.topAnchor.constraint(equalTo: topAnchor), container.bottomAnchor.constraint(equalTo: bottomAnchor), container.leadingAnchor.constraint(equalTo: leadingAnchor), container.trailingAnchor.constraint(equalTo: trailingAnchor) ]) if let contentView = contentView { setup(contentView: contentView, in: container) } DispatchQueue.main.async { self.preventScreenCapture = true } } private func setup(contentView: UIView) { self.contentView?.removeFromSuperview() self.contentView = contentView guard let container = hiddenContentContainer else { return } container.addSubview(contentView) container.isUserInteractionEnabled = isUserInteractionEnabled contentView.translatesAutoresizingMaskIntoConstraints = false let bottomConstraint = contentView.bottomAnchor.constraint(equalTo: container.bottomAnchor) bottomConstraint.priority = .required - 1 NSLayoutConstraint.activate([ contentView.leadingAnchor.constraint(equalTo: container.leadingAnchor), contentView.trailingAnchor.constraint(equalTo: container.trailingAnchor), contentView.topAnchor.constraint(equalTo: container.topAnchor), bottomConstraint ]) } } HiddenContainerRecognizer.swift struct HiddenContainerRecognizer { private enum Error: Swift.Error { case unsupportedOSVersion(version: Float) case desiredContainerNotFound(_ containerName: String) } func getHiddenContainer(from view: UIView) throws -> UIView { let containerName = try getHiddenContainerTypeInStringRepresentation() let containers = view.subviews.filter { subview in type(of: subview).description() == containerName } guard let container = containers.first else { throw Error.desiredContainerNotFound(containerName) } return container } private func getHiddenContainerTypeInStringRepresentation() throws -> String { if #available(iOS 15, *) { return "_UITextLayoutCanvasView" } if #available(iOS 14, *) { return "_UITextFieldCanvasView" } if #available(iOS 13, *) { return "_UITextFieldCanvasView" } if #available(iOS 12, *) { return "_UITextFieldContentView" } let currentIOSVersion = (UIDevice.current.systemVersion as NSString).floatValue throw Error.unsupportedOSVersion(version: currentIOSVersion) } } How I use it in my Screen let container = ScreenshotPreventingView() override func viewDidLoad() { super.viewDidLoad() container.preventScreenCapture = true container.setup(contentView: viewContainer) //viewContainer is UIView in storyboard, in which all other UI elements are placed in e.g. UITableView self.view.addSubview(container) container.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ container.topAnchor.constraint(equalTo: self.view.topAnchor), container.bottomAnchor.constraint(equalTo: self.view.bottomAnchor), container.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), container.trailingAnchor.constraint(equalTo: self.view.trailingAnchor) ]) } What I’d Like to Confirm Is this approach acceptable for App Store submission? Is there a more Apple-recommended approach to prevent screen capture of arbitrary UI? Thank you for your help in ensuring compliance.
0
0
78
1w
Cursor Misalignment When Selecting List Options – macOS Tahoe 26.0 Developer Beta 2
Since updating my MacBook Air to macOS Tahoe 26.0 Developer Beta 2, I’ve encountered a persistent cursor misalignment issue: When interacting with lists or contextual menus, the cursor’s visual position does not align with what it actually selects. The system registers the cursor slightly above where it appears, causing clicks to select the wrong option or fail to register. As a temporary workaround, I can sometimes position the cursor off-target and press Enter to select, but this is a frustrating and inefficient workaround. The issue persists after a restart and appears across multiple areas of the OS: Right-clicking an app in the Dock to open the contextual menu → cursor highlights an incorrect item relative to its position. In System Settings menus. Even on the Feedback Assistant site when selecting issue categories. Steps to Reproduce: 1️⃣ Update to macOS Tahoe 26.0 Developer Beta 2 on MacBook Air. 2️⃣ Right-click on any open application in the Dock. 3️⃣ Attempt to select an option from the list that appears. 4️⃣ Observe that the cursor highlights or interacts with a different option than where the cursor is visibly located. Notes: Issue is consistent across reboots. Affects workflow and general navigation. Temporary workaround using keyboard navigation is insufficient for productivity. FB Number: FB18531124 If others are seeing this as well, please confirm below so Apple can prioritize investigation.
2
1
112
2w
UINavigationController retain cycle in iOS 26
Verbatim of a feedback report (FB18431713) I submitted, duplicated here since we can't see each other's feedbacks, and I wanted a centralized place to track the resolution of this as I'm surely not the only one facing this. When building the app using Xcode 26 beta 2 and running it in an iOS 26 simulator, I'm experiencing a retain cycle in the UINavigationController. From the data I saw in Xcode's memory graph debugger, it seems that _UIViewControllerOneToOneTransitionContext is retaining it. I base this on the fact that the line connecting a view controller and _UIViewControllerOneToOneTransitionContext has a "strong" reference, as indicated in Xcode. (However, I'm reporting this as a retain cycle in UINavigationController, as that's what seems to hold onto this transition-context.)
0
0
75
3w
SwiftUI buttons behind NSToolbarView are not clickable on macOS 26 beta
Overview Starting with macOS 26 beta 1, a new NSGlassContainerView is added inside NSToolbarView. This view intercepts mouse events, so any SwiftUI Button (or other interactive view) overlaid on the title‑bar / toolbar area no longer receives clicks. (The same code works fine on macOS 15 and earlier.) Filed as FB18201935 via Feedback Assistant. Reproduction (minimal project) macOS 15 or earlier → button is clickable macOS 26 beta → button cannot be clicked (no highlight, no action call) @main struct Test_macOS26App: App { init() { // Uncomment to work around the issue (see next section) // enableToolbarClickThrough() } var body: some Scene { WindowGroup { ContentView() } .windowStyle(.hiddenTitleBar) // ⭐️ hide the title bar } } struct ContentView: View { var body: some View { NavigationSplitView { List { Text("sidebar") } } detail: { HSplitView { listWithOverlay listWithOverlay } } } private var listWithOverlay: some View { List(0..<30) { Text("item: \($0)") } .overlay(alignment: .topTrailing) { // ⭐️ overlay in the toolbar area Button("test") { print("test") } .glassEffect() .ignoresSafeArea() } } } Investigation In Xcode View Hierarchy Debugger, a layer chain NSToolbarView > NSGlassContainerView sits in front of the button. -[NSView hitTest:] on NSGlassContainerView returns itself, so the event never reaches the SwiftUI layer. Swizzling hitTest: to return nil when the result is the view itself makes the click go through: func enableToolbarClickThrough() { guard let cls = NSClassFromString("NSGlassContainerView"), let m = class_getInstanceMethod(cls, #selector(NSView.hitTest(_:))) else { return } typealias Fn = @convention(c)(AnyObject, Selector, NSPoint) -> Unmanaged<NSView>? let origIMP = unsafeBitCast(method_getImplementation(m), to: Fn.self) let block: @convention(block)(AnyObject, NSPoint) -> NSView? = { obj, pt in guard let v = origIMP(obj, #selector(NSView.hitTest(_:)), pt)?.takeUnretainedValue() else { return nil } return v === (obj as AnyObject) ? nil : v // ★ make the container transparent } method_setImplementation(m, imp_implementationWithBlock(block)) } Questions / Call for Feedback Is this an intentional behavioral change? If so, what is the recommended public API or pattern for allowing clicks to reach views overlaid behind the toolbar? Any additional data points or confirmations are welcome—please reply if you can reproduce the issue or know of an official workaround. Thanks in advance!
2
0
143
Jun ’25
encounter memory leak for SVG image
I have a memory leak for SVG image that located in Assets.xcassets file when using SwiftUI Image, but when I use UIImage then convert it to SwiftUI Image the issue is not found. import SwiftUI struct ContentView: View { var body: some View { NavigationStack { VStack { NavigationLink("Show", destination: SecondView()) } .padding() } } } struct SecondView: View { @Environment(\.dismiss) var dismiss var body: some View { NavigationStack { VStack { IM.svgImage .resizable() .scaledToFit() .frame(width: 200, height: 200) Button("Dismiss") { dismiss() } } } } } enum IM { static let testImage: Image = "test_image".image static let svgImage: Image = "svgImage".image } extension String { var image: Image { Image(self) // Memory leak } var imageFromUIImage: Image { guard let uiImage = UIImage(named: self) else { return Image(self) } return Image(uiImage: uiImage) // No Memory leak } } Environment that produces the issue: Xcode: 16.2 Simulator: iPhone 15 Pro (iOS 17.5)
1
0
53
Jun ’25
Issues with .zoom NavigationTransition to a sheet with a .medium detent
When using a .zoom navigation transition, where .matchedTransitionSource is applied to a button in a toolbar and the destination view is a sheet which is presented with PresentationDetent.medium, the transition works initially, but shortly after it completes, the sheet's background is dimmed and the text of the source button reappears abruptly. Code and a screenshot are below, though the effect is best observed when interacting with the view. // // ContentView.swift // ZoomNavigationTransitionSample // // Created by Matthew DuBois on 6/15/25. // import SwiftUI struct ContentView: View { @State private var isPresentingSheet = false @Namespace private var namespace var body: some View { NavigationStack { List { Text("Some content") } .navigationTitle("Sample") .toolbar { ToolbarItem(placement: .topBarTrailing) { Button("Button") { isPresentingSheet = true } .matchedTransitionSource(id: "button", in: namespace) } } .sheet(isPresented: $isPresentingSheet) { Text("Some sheet content") .navigationTransition(.zoom(sourceID: "button", in: namespace)) .presentationDetents([.medium]) } } } } #Preview { ContentView() }
1
1
49
Jun ’25
Using .glassEffect in Charts
Hi, I was wondering if it's possible (and advisable) to use the new glass effects available in iOS 26 in Swift Charts? For example, in a chart like the one in the image I've attached to this post, I was looking to try adding a .glassEffect modifier to the BarMarks to see how that would look and feel. However, it seems it's not available directly on the BarMark (ChartContent) type, and I'm having trouble adding it in other ways too, such as using in on the types I supply to modifiers like foregroundStyle or clipShape. Am I missing anything? Maybe it's just not advisable or necessary to use glass effects within Charts?
3
0
128
Jun ’25
The NSTextViewDelegate method textViewDidChangeSelection(:) will not fire, while all other text view delegate methods do.
I am trying to implement the NSTextViewDelegate function textViewDidChangeSelection(_ notification: Notification). My text view's delegate is the Coordinator of my NSViewRepresentable. I've found that this delegate function never fires, but any other delegate function that I implement, as long as it doesn't take a Notification as an argument, does fire (e.g., textView(:willChangeSelectionFromCharacterRange:toCharacterRange:), fires and is called on the delegate exactly when it should be). For context, I've verified all of the below: textView.isSelectable = true textView.isEditable = true textView.delegate === my coordinator I can call textViewDidChangeSelection(:) directly on the delegate without issue. I can select and edit text without issues. I.e., the selections are being set correctly. But the delegate method is never called when they are. I am able to add the intended delegate as an observer for the selector textViewDidChangeSelection via NotificationCenter. If I do this, the function executes when it should, but fires for every text view in my view hierarchy, which can number in the hundreds. I'm using an NSLayoutManager, so I figure this should only fire once. I've added a check within my code: func textViewDidChangeSelection(_ notification: Notification) { guard let textView = notification.object as? NSTextView, textView === layoutManager.firstTextView else { return } // Any code I want to execute... } But the above guard check lets through every notification, so, no matter what, my closure executes hundreds of times if I have hundreds of text views, all of them being sent by textView === layoutManager.firstTextView, but once for each and every text view managed by that layoutManager. Does anyone know why this method isn't ever called on the delegate, while seemingly all other delegate methods are? I could go the NotificationCenter route, but I'd love to know why this won't execute as a delegate method when documentation says that it should, and I don't want to have to implement a counter to make sure my code only executes once per selection update. And for more reasons than that, implementing via delegate method is preferable to using notifications for my use case. Thanks for any help!
3
0
104
May ’25
memory leak/increased memory by NSTextField setString
I just put the TextField on UI and call the NSTextField setString, but it is memory usage is increasing. StoryBoard Objective C put TextField and button to UI set TextField variable to "ABC" in ViewController.h @property (weak) IBOutlet NSTextView* ABC; on button event function //dispatch_sync(dispatch_get_main_queue(), ^{ [_ABC setString:str]; //}); How to block the memory usage increase? Also I was check on Instruments app, and there are many malloc 48bytes, its count is almost same with setString count. Thank you!
1
0
75
May ’25
Get MacOS menubar size in Swift
To get menubar size, we can call. let menuBarHeight = NSStatusBar.system.thickness That is returning 24 and it is the same as my external screen. I did command + shift + 5 and use the screen capture tool to rougly measure the size of menubar. It is roughly 24px. However, for my macbook pro 14 inches m2 pro. The menubar seem thicker because of the webcam. Is there a way to find out the size in Swift?
2
1
132
Apr ’25
listRowSeparatorTint not updated
This sample code exhibits two issues: struct ContentView: View { @State private var myColor = Color.red var body: some View { VStack() { List() { Text("Object") Text("Object") Text("Object") .listRowSeparatorTint(myColor) Text("Object") } Button(action:{myColor = Color.green}) {Text("Change color")} } .foregroundColor(myColor) } } the row separator isn't redraws when the @State property change listRowSeparatorTint apply to two lines The first point is really disappointing. Is there anyone which know if this is a bug or there is a more correct way to use listRowSeparatorTint with changing parameter?
2
0
123
Apr ’25
Unexpected onAppear behavior in NavigationStack with ViewThatFits
Hello, My goal is to have a NavigationStack whose root view is determined based on its height and width. To do so, I'm using ViewThatFits, which should choose the right view to display. It is working fine, but unexpectedly both views trigger onAppear, whereas only the appropriate one should. This causes the logic in both closures to be executed, which is not intended. The code below demonstrates the problem: struct NavigationStackContentView: View { var body: some View { NavigationStack { ViewThatFits(in: .vertical) { Color.yellow .onAppear { print("|-> on appear: yellow") } .onDisappear { print("|-> on disappear: yellow") } Color.red .frame(width: 1500, height: 1500) .onAppear { print("|-> on appear: red") } .onDisappear { print("|-> on disappear: red") } } } } } this produces: |-> on appear: red |-> on disappear: red |-> on appear: yellow When ViewThatFits is not nested within NavigationStack, the problem does not occur — only the yellow view (in this sample) triggers onAppear, which is the expected behavior. I also checked the macOS version, and the problem does not occur at all, whether within NavigationStack or not. This example is simple and demonstrates that the larger view is the second one. When I switch their places, the problem does not occur because it recognizes that the first view would not fit at this point. However, in my case I will have these views without knowing which one will not fit, so switching their order is not a viable solution if this works without NavigationStack. Am I doing something wrong, or is this a bug? // iOS: 18.3.1 Xcode: 16.2
1
0
163
Mar ’25
PHPickerViewController No Auto Focus
The issue is, I cannot auto acquire bluetooth keyboard focus in PHPickerViewController after enabling 'Full Keyboard Access' in my IPhone 14 with iOS version 18.3.1. The keyboard focus in PHPickerViewController will show, however, after I tapped on the blank space of the PHPickerViewController. How to make the focus on at the first place then? I'm using UINavigationController and calling setNavigationBarHidden(true, animated: false). Then I use this controller to present PHPickerViewController using some configuration setup below. self.configuration = PHPickerConfiguration() configuration.filter = .any(of: filters) configuration.selectionLimit = selectionLimit if #available(iOS 15.0, *), allowOrdering { configuration.selection = .ordered } configuration.preferredAssetRepresentationMode = .current Finally I set the delegate to PHPickerViewController and call UINavigationController.present(PHPickerViewController, animated: true) to render it. Also I notice animation showing in first video then disappear.
2
0
240
Mar ’25
Implement two lists side by side with SwiftUI on iPad
I'm currently building an App using a TabView as the main navigation method. In my app I would like to build a page similar to the Top Charts in the native App Store App with two lists side by side: So far I came up with this code (simplified demo): import SwiftUI struct Demo: View { var body: some View { TabView { Tab("Main Tab", systemImage: "tray.and.arrow.down.fill") { NavigationStack { HStack { List { Text("Left List") } List { Text("Right List") } } .navigationTitle("Demo") .navigationBarTitleDisplayMode(.inline) } } } } } #Preview { Demo() } However, I’m encountering a couple of issues: • Scrolling to the top of the left list doesn’t trigger the toolbar background effect, and the content overlaps with the tabs in a strange way. Scrolling to the top of the right list works as expected. • The navigation title is always hidden. I haven’t been able to find a solution to these problems. What would be the correct approach? Thank you!
1
0
524
Jan ’25
iPadOS 18 TabView with Large Navigation Title
I’m following the example code from Apple to implement the new iPadOS 18 TabView() with the new Tab(). While the tabbing itself is working fine, I can’t get it to show up a (large) navigation title in the sidebar (like the Home or Files app). I’ve tried placing .navigationTitle("App Name") at the TabView, but that doesn’t work. Is it possible to do this in any way or is this not recommended to show? TabView { Tab("Overview", systemImage: "film") { Text("Put a OverviewView here") } TabSection("Watch") { Tab("Movies", systemImage: "film") { Text("Put a MoviesView here") } Tab("TV Shows", systemImage: "tv") { Text("Put a TVShowsView here") } } TabSection("Listen") { Tab("Music", systemImage: "music.note.list") { Text("Put a MusicView here") } Tab("Podcasts", systemImage: "mic") { Text("Put a PodcastsView here") } } } .tabViewStyle(.sidebarAdaptable) .navigationTitle("App Name") .navigationBarTitleDisplayMode(.large) I know that there is also the .tabViewSidebarHeader() modifier, but that adds any view above the scroll view content. Neither does that easily allow to make it look like the regular navigation title, nor does it actually display in the navigation bar at the top, when scrolling down.
2
0
886
Dec ’24
traitCollectionDidChange iOS18
iOS18.2 / iPhone 16pro / Xcode 16.2 'traitCollectionDidChange' This function has been deprecated since ios17. However, in ios18, when I changed the app to the background state or changed it to the foreground state again, it was confirmed that the function worked. It hasn't been confirmed in ios17, but why is it only confirmed in ios18?
0
0
583
Dec ’24