I have an NSWindowController with several IBOutlets created in storyboard.
I want to add an NSView and fill it with some color. I need to place it at a specific position in views hierarchy.
I have tried 2 ways, no one succeeds.
First.
include a custom view in storyboard
connect to an IBOutlet
in an init of controller, set the layer for the view
Result: crash
Second
build programmatically
Result: I do not find where to put this code in the controller code
That's basic Cocoa, but way more painful than iOS.
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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
Memory leak in CarPlay when using CPTabBarTemplate
Reproduced using the code example "Integrating CarPlay with Your Music App" from the official Apple documentation - https://developer.apple.com/documentation/carplay/integrating-carplay-with-your-music-app
Steps to reproduce the leak:
Download and run the example on CarPlay.
Select the Settings tab.
Click the first item in the list "Use Apple Music".
Click Back button.
Repeat steps 3 and 4 several times.
Open Debug Memory Graph in xCode and search for "CPGridTemplate" - the count will be greater than 0.
Conditions under which the memory leak disappears:
If you open and switch to all tabs one by one, the leak disappears.
Hello,
We're having massive issues when we nest LazyVStacks inside a ScrollView. Our app relies heavily on custom views that are sometimes nested two or three levels deep. While the app does work fine overall, we see a massive spike in CPU usage in Instruments when accessibility features like VoiceOver are enabled. Those spikes never recover, so the app basically freezes and stays that way until force quit.
We are in talks with a third-party service that uses accessibility features we want to use. Fortunately they have created a GitHub repository which recreates the issue we're facing.
It would be greatly appreciated if someone could have a look at the code and tell us what the issue is, or if there's some kind of workaround.
Here's the link to the repo: https://github.com/pendo-io/SwiftUI_Hang_Reproduction.
Just to be clear, the issue is not directly related to the third-party SDK, but to the accessibility features used in conjunction with SwiftUI. As you can see in the repo the issue is reproducible without having the SDK included in the project.
Thanks in advance
I have written this function:
@available(macOS 26.0, *)
func instancing() async -> Entity {
let entity = Entity()
do {
// 1. Create a CustomMaterial
let library = offscreenRenderer.pointRenderer!.device.makeDefaultLibrary()!
let surfaceShader = CustomMaterial.SurfaceShader(
named: "surfaceShaderWithCustomUniforms", // This must match the function name in Metal
in: library
)
let instanceCount = 10
// No idea how to actually use this...
// let bufferSize = instanceCount * MemoryLayout<UInt32>.stride
//
// // Create the descriptor
// var descriptor = LowLevelBuffer.Descriptor(capacity: bufferSize, sizeMultiple: MemoryLayout<UInt32>.stride)
//
// // Initialize the buffer
// let lowLevelBuffer = try LowLevelBuffer(descriptor: descriptor)
// lowLevelBuffer.withUnsafeMutableBytes { rawBytes in
// // Bind the raw memory to the UInt32 type
// let pointer = rawBytes.bindMemory(to: UInt32.self)
// pointer[1] = 0xff_0000
// pointer[0] = 0x00_ff00
// pointer[2] = 0x00_00ff
// pointer[3] = 0xff_ff00
// pointer[4] = 0xff_00ff
// pointer[5] = 0x00_ffff
// pointer[6] = 0xff_ffff
// pointer[7] = 0x7f_0000
// pointer[8] = 0x00_7f00
// pointer[9] = 0x00_007f
// }
var material = try CustomMaterial(surfaceShader: surfaceShader, lightingModel: .lit)
material.withMutableUniforms(ofType: SurfaceCustomUniforms.self, stage: .surfaceShader) { params, resources in
params.argb = 0xff_0000
}
// 2. Create the ModelComponent (provides the MESH and MATERIAL)
let mesh = MeshResource.generateSphere(radius: 0.5)
let modelComponent = ModelComponent(mesh: mesh, materials: [material])
// 3. Create the MeshInstancesComponent (provides the INSTANCE TRANSFORMS)
let instanceData = try LowLevelInstanceData(instanceCount: instanceCount)
instanceData.withMutableTransforms { transforms in
for i in 0..<instanceCount {
let instanceAngle = 2 * .pi * Float(i) / Float(instanceCount)
let radialTranslation: SIMD3<Float> = [-sin(instanceAngle), cos(instanceAngle), 0] * 4
// Position each sphere around a circle.
let transform = Transform(
scale: .one,
rotation: simd_quatf(angle: instanceAngle, axis: [0, 0, 1]),
translation: radialTranslation
)
transforms[i] = transform.matrix
}
}
let instancesComponent = try MeshInstancesComponent(mesh: mesh, instances: instanceData)
// 4. Attach BOTH to the same entity
entity.components.set(modelComponent)
entity.components.set(instancesComponent)
} catch {
print("Failed to create mesh instances: \(error)")
}
return entity
}
and this is the corresponding Metal shader
typedef struct {
uint32_t argb;
} SurfaceCustomUniforms;
[[stitchable]]
void surfaceShaderWithCustomUniforms(realitykit::surface_parameters params,
constant SurfaceCustomUniforms &customParams)
{
half3 color = {
static_cast<half>((customParams.argb >> 16) & 0xff),
static_cast<half>((customParams.argb >> 8) & 0xff),
static_cast<half>(customParams.argb & 0xff) };
params.surface().set_base_color(color);
}
which works well and generates 10 red spheres. While listening to the WWDC25 presentation on what's new in RealityKit I am positive to hear the presenter saying that it is possible to customise each instance using a LowLevelBuffer, but so far all my attempts have failed.
Is it possible, and if so how ?
Thanks for reading and for your help.
Kind regards,
Christian
Overview
In iOS 26, a List embedded in a NavigationStack inside a TabView exhibits a visual glitch when switching tabs.
When the list is scrolled such that some rows are partially obscured by the navigation bar, the system correctly applies a fade/opacity effect to those rows. However, if the user switches to another tab while rows are in this partially obscured (faded) state, those rows briefly flash at full opacity during the tab transition before disappearing.
This flash is visually distracting and appears to be inconsistent with the intended scroll-edge opacity behavior.
The issue occurs only for rows partially obscured by the navigation bar.
Rows partially obscured by the tab bar do not exhibit this flashing behavior.
Steps to Reproduce:
Run the attached minimal reproduction on iOS 26.
Open the first tab.
Scroll the list so that some rows are partially hidden behind the navigation bar (showing the native faded appearance).
While rows are in this partially faded state, switch to the second tab.
Observe that the faded rows briefly render fully opaque during the tab switch.
Expected Behavior:
Rows that are partially obscured by the navigation bar should maintain consistent opacity behavior during tab transitions, without flashing to full opacity.
import SwiftUI
@main
struct NavBarReproApp: App {
/// Minimal repro for iOS 26:
/// - TabView with two tabs
/// - First tab: NavigationStack + List
/// - Scroll so some rows are partially behind the nav bar (faded)
/// - Switch tabs: those partially-faded rows briefly flash fully opaque. Partially faded rows under the tab bar do not flash
private let items = Array(0..<200).map { "Row \($0)" }
var body: some Scene {
WindowGroup {
TabView {
NavigationStack {
List {
ForEach(items, id: \.self) { item in
Text(item)
}
}
.navigationTitle("One")
.navigationBarTitleDisplayMode(.inline)
}
.tabItem { Label("One", systemImage: "1.circle") }
NavigationStack {
Text("Second tab")
.navigationTitle("Two")
.navigationBarTitleDisplayMode(.inline)
}
.tabItem { Label("Two", systemImage: "2.circle") }
}
}
}
}
If I delete Safari and only have another browser installed on my device, UIApplication.shared.open does not work. I think this is a bug. Why would it not work?
If Safari is not the main browser, UIApplication would open the URL in my main browser.
Those are valid use cases.
I would expect this API to work with any browser...
iOS 26.2
iPhone 14 Pro
guard let url = URL(string: "https://www.apple.com") else {
return
}
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
} else {
print("Could not open URL")
}
Topic:
UI Frameworks
SubTopic:
UIKit
Hi all,
When navigating between two screens where the first uses .inline and the second .large title display mode, the NavigationBar shows visible resizing glitches during the push animation.
This is especially noticeable when using a custom background color (e.g. yellow) via UINavigationBarAppearance or .toolbarBackground(Color.yellow, for: .navigationBar).
I’m already using the same appearance for standard, scrollEdge, and compact, with configureWithOpaqueBackground(), but the issue remains.
Is this a known UIKit or SwiftUI issue?
Any recommended workaround?
Thanks.
Topic:
UI Frameworks
SubTopic:
SwiftUI
In SwiftUI, it is recommended not to store ViewBuilder closures in sub-views but instead evaluate them directly in init and store the result (example: https://www.youtube.com/watch?v=yXAQTIKR8fk). That has the advantage, as I understand it, that the closure doesn't need to be re-evaluated on every layout pass.
On the other side, identity is a very important topic in SwiftUI to get the UI working properly.
Now I have this generic view I'm using with a closure which is displayed in two places (HStack & VStack). Should I store the closure result and get the performance improvements, or evaluate it in place and get correct identities (if that is even an issue)?
Simplified example:
struct DynamicStack<Content: View>: View {
@ViewBuilder var content: () -> Content
var body: some View {
ViewThatFits(in: .horizontal) {
HStack {
content()
}
VStack {
content()
}
}
}
}
vs
struct DynamicStack<Content: View>: View {
@ViewBuilder var content: Content
var body: some View {
ViewThatFits(in: .horizontal) {
HStack {
content
}
VStack {
content
}
}
}
}
When a Menu is placed inside a ToolbarItem, applying
buttonStyle(.glassProminent) has no visible effect.
The same modifier works correctly when a Button is used instead of a Menu inside the ToolbarItem. In that case, the button is rendered with the accent-colored background as expected.
This suggests that Menu does not respect the .glassProminent button style when embedded in a ToolbarItem, even though other button types do.
Code Example
// Button with accent background color
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: {})
.buttonStyle(.glassProminent)
}
}
// Menu with internal button with no accent background color
.toolbar {
ToolbarItem(placement: .primaryAction) {
Menu(...) {
...
}.buttonStyle(.glassProminent)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
That's a question for Mac app (Cocoa).
I want to change the standard highlighting.
I thought to use tableView.selectionHighlightStyle.
But there are only 2 values: .none and .regular. Cannot find how to define a custom one.
So I tried a workaround:
set tableView.selectionHighlightStyle to .none
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
tableView.selectionHighlightStyle = .none
keep track of previousSelection
Then, in tableViewSelectionDidChange
reset for previousSelection
func tableViewSelectionDidChange(_ notification: Notification) { }
if previousSelection >= 0 {
let cellView = theTableView.rowView(atRow: previousSelection, makeIfNecessary: false)
cellView?.layer?.backgroundColor = .clear
}
set for the selection to a custom color
let cellView = theTableView.rowView(atRow: row, makeIfNecessary: false)
cellView?.layer?.backgroundColor = CGColor(red: 0, green: 0, blue: 1, alpha: 0.4)
previousSelection = row
Result is disappointing :
Even though tableView.selectionHighlightStyle is set to .none, it does overlays the cellView?.layer
Is there a way to directly change the color for selection ?
I am implementing an AI chat application and aiming to achieve ChatGPT-like behavior. Specifically, when a new message is sent, the ScrollView should automatically scroll to the top to display the latest message.
I am currently using the scrollTo method for this purpose, but the behavior is inconsistent—sometimes it works as expected, and other times it does not. I’ve noticed that this issue has been reported in multiple places, which suggests it may be a known SwiftUI limitation.
I’d like to know:
Has this issue been fixed in recent SwiftUI versions, or does it still persist?
If it still exists, is there a reliable solution or workaround that anyone can recommend?
iOS 26 SwiftUI .glassEffect() renders dark/gray on physical device - TestFlight doesn't fix it
.glassEffect() renders as dark/muddy gray on my physical iPhone instead of the light frosted glass like Apple Music's tab bar.
What I've confirmed:
Same code works perfectly on iOS Simulator
Apple Music and other Apple apps show correct Liquid Glass on same device
Brand new Xcode project with just .glassEffect() also renders dark
TestFlight build (App Store signing) has the SAME problem - still dark/gray
This rules out developer signing vs App Store signing as the cause
What I've tried:
Clean build, delete derived data, reinstall app
Completely reinstalled Xcode
All accessibility settings correct (Reduce Transparency OFF, Liquid Glass set to Clear)
Disabled Metal diagnostics
Debug and Release builds
Added window configuration for Extended sRGB/P3 color space
Added AppDelegate with configureWindowForLiquidGlass()
Tried .preferredColorScheme(nil)
Tried background animation to force "live" rendering
Environment:
iPhone 17 Pro, iOS 26.3
Xcode 26.2
macOS 26.3
The question:
Why does .glassEffect() work for Apple's apps but not third party apps, even with App Store signing via TestFlight? What am I missing?
OS 26.s, Xcode 26.2
TLDR: My pure SwiftUI app freezes the window server, is this a known problem?
My app is pure SwiftUI, no low level calls, no networking, no tricksy pointer use. Somehow, something in my code is terminally confusing the Window Server. As in, I run the app, and before I ever seen a window, the Window Server locks up, and is killed by the OS for being unresponsive.
Using debugging shows that I get to the end of a Canvas, and it simply freezes upon exiting.
I'm about to do the old comment out everything, and bring it back a bit at a time, but I'm wondering if anyone is experiencing this sort of thing? The reaction is so extreme.
And it's not Xcode in particular, I built the program with xcodebuild, Xcode itself not running, and ran my app, and it did the same thing.
Topic:
UI Frameworks
SubTopic:
SwiftUI
I had take screenshots by following code
let scenes = UIApplication.shared.connectedScenes
let windowScene = scenes.first as? UIWindowScene
let window = windowScene?.windows.first
self.uiImage = window?.rootViewController?.view!.getImage(rect: rect)
View has two views. One is ImageView contains some image and overlay of image detection results with .overlay. another view is InfoView contains several info and button which above code fired. on iOS 17, I can take screenshots as I saw, but on iOS26, missing on image of ImageView. Overlay(detected rectangle) in Imageview and InfView can be taken.
How can I take screenshots as I saw on iOS26?(iPad)
I have an Apple TV photo slideshow app (Objective-C, Storyboard based, transitioned to scenes and UIKit from old Appdelegate model) which is trivial but exhibits a problem I can't fix. The app has 2 UIImageViews, pulls photos from iCloud, replaces the back view, fades between them, swaps front and back images. I cannot for the life of me work out how to tell tvOS / UIKit that I need to stay in the foreground. Other slideshow apps manage it, clearly movie viewing apps like Netflix, Disney+ and BBC iPlayer manage to stay on top without the user needing to interact with the UI, but I keep getting pushed out. The pushing out happens only if I am playing music on the Apple TV, either using the built-in music app or AirPlaying music to the Apple TV from an iPad or phone.
The issue is reproducible in an app that does nothing except load up a photo from the main bundle into a UIImageView. It's as if the OS thinks I'm idle and I need to nudge it to remind it I'm still here, but I can find no hints in Apple's documentation as to how I should do this.
Project of trivial app here : https://drive.google.com/file/d/1eY_nQJ7adHEgAvFwhS-t38dqBEPVovub/view?usp=sharing
Topic:
UI Frameworks
SubTopic:
UIKit
Hey there guys, I'm new on SwiftUI and iOS Development world.
How can I achieve a seamless TabBar transition in SwiftUI? Currently, when I programmatically hide the TabBar on a pushed view and swipe back to the previous view, there is a noticeable delay before the TabBar reappears. How can I make it appear instantly?
Here is the link to the video https://streamable.com/3zz2o2
Thank you in advance
Topic:
UI Frameworks
SubTopic:
SwiftUI
Our project include UIKIt and SwiftUI, and in some case, we need to traverse all subviews, for UIKit implement views, below code:
func findView(byIdentifier identifier: String) -> UIView? {
if self.accessibilityIdentifier == identifier {
return self
}
for subview in subviews {
if let found = subview.findView(byIdentifier: identifier) {
return found
}
}
return nil
}
works well, but for SwiftUI implement views, like below code:
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
.accessibilityIdentifier("Image")
Text("Hello, world!")
.accessibilityIdentifier("Text")
}
.padding()
}
}
it can not find subviews in the ContentView, and only a view with type:
_UIHostingView<ModifiedContent<AnyView, RootModifier>>
can be found, the Image and Text is not found;
And because we have set a accessibilityIdentifier property, so we also try use:
@MainActor
var accessibilityElements: [Any]? { get set }
to find sub node, but this accessibilityElements is not stable, we can find the Image and Text node in iOS26.1 system:
[AX] level=3 AccessibilityNode @ 0x000000010280fb10 id=Image
[AX] level=3 AccessibilityNode @ 0x000000010161fbf0 id=Text
but can not find it in iOS26.0 and below system.
Any suggestion in how to find SwiftUI subviews? thank you
Topic:
UI Frameworks
SubTopic:
SwiftUI
I have a MacOS app which displays PDFs, and I want to create a New document from the Clipboard, if the clipboard contains valid graphical data.
My problem is that even if it doesn't, I still get a blank new document window. AppKit always creates a new document.
I've tried overriding the newDocument function; I've tried avoiding the built-in functions altogether.
Are there any general recommendations for going about this?
I have a custom UI to display date (for user birthday) and want if the user presses each part of the label , the date selection is displayed, the current issue is , when I try to reduce the DatePicker opacity or set the colorMultipli to clear color, it still clickable on the date area, while my object is a fullWidth object, how can I fix it?
This is the code:
VStack(alignment: .leading, spacing: 8) {
Text("Birthday")
.font(.SFProText.font(type: .medium, size: 13))
.foregroundStyle(Color(uiColor: .label))
HStack(alignment: .center) {
Text(userProfileAccountInfoviewModel.birthday.getShortFormat(format: "dd MMM yyyy"))
.font(.SFProText.font(type: .medium, size: 13))
.foregroundColor(Color(uiColor: .label))
.padding(.horizontal, 13)
Spacer()
}
.frame(height: 44)
.contentShape(Rectangle())
.overlay {
HStack {
DatePicker(selection: $userProfileAccountInfoviewModel.birthday, displayedComponents: .date) {}
.labelsHidden()
.colorMultiply(.clear)
.background(Color.clear)
.foregroundStyle(Color.baseBackgroundSecondary)
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
// .opacity(0.011)
Spacer()
}
}
.background(Color.baseBackgroundSecondary)
.clipShape(RoundedRectangle(cornerRadius: 4))
}
Hey all,
I found a weird behaviour with the searchable component. I created a custom bottom nav bar (because I have custom design in my app) to switch between screens.
On one screen I display a List component with the searchable component. Whenever I enter the search screen the first time, the searchable component is displayed at the bottom.
This is wrong. It should be displayed at the top under the navigationTitle. When I enter the screen a second time, everything is correct.
This behaviour can be reproduced on all iOS 26 versions on the simulator and on a physical device with debug and release build.
On iOS 18 everything works fine.
Steps to reproduce:
Cold start of the app
Click on Search TabBarIcon (searchable wrong location)
Click on Home TabBarIcon
Click on Search TabBarIcon (searchable correct location)
Simple code example:
import SwiftUI
struct ContentView: View {
@State var selectedTab: Page = Page.main
var body: some View {
NavigationStack {
ZStack {
VStack {
switch selectedTab {
case .main:
MainView()
case .search:
SearchView()
}
}
VStack {
Spacer()
VStack(spacing: 0) {
HStack(spacing: 0) {
TabBarIcon(iconName: "house", selected: selectedTab == .main, displayName: "Home")
.onTapGesture {
selectedTab = .main
}
TabBarIcon(iconName: "magnifyingglass", selected: selectedTab == .search, displayName: "Search")
.onTapGesture {
selectedTab = .search
}
}
.frame(maxWidth: .infinity)
.frame(height: 55)
.background(Color.gray)
}
.ignoresSafeArea(.all, edges: .bottom)
}
}
}
}
}
struct TabBarIcon: View {
let iconName: String
let selected: Bool
let displayName: String
var body: some View {
ZStack {
VStack {
Image(systemName: iconName)
.resizable()
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.foregroundColor(Color.black)
.frame(width: 22, height: 22)
Text(displayName)
.font(Font.system(size: 10))
}
}
.frame(maxWidth: .infinity)
}
}
enum Page {
case main
case search
}
struct MainView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
.navigationTitle("Home")
}
}
struct SearchView: View {
@State private var searchText = ""
let items = [
"Apple",
"Banana",
"Pear",
"Strawberry",
"Orange",
"Peach",
"Grape",
"Mango"
]
var filteredItems: [String] {
if searchText.isEmpty {
return items
} else {
return items.filter {
$0.localizedCaseInsensitiveContains(searchText)
}
}
}
var body: some View {
List(filteredItems, id: \.self) { item in
Text(item)
}
.navigationTitle("Fruits")
.searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .always), prompt: "Search")
}
}